diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-27 14:40:10 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-27 14:40:10 +0000 |
commit | 39ef9a4855c593f1ea3a6bb122d5c22a50b371cb (patch) | |
tree | f0e08aa22b6c9260d3cb3c7fb0e7b8dea72ae560 /collaboration/wink-helloworld-sca/src/test/java/org/apache/wink | |
parent | edce121c4ed65d77bdd4a66501b04fefc0c637f6 (diff) |
Copy of the Apache Wink HelloWorld example updated to show an approach to SCA integration
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@903659 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration/wink-helloworld-sca/src/test/java/org/apache/wink')
-rw-r--r-- | collaboration/wink-helloworld-sca/src/test/java/org/apache/wink/example/helloworld/HelloWorldTest.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/collaboration/wink-helloworld-sca/src/test/java/org/apache/wink/example/helloworld/HelloWorldTest.java b/collaboration/wink-helloworld-sca/src/test/java/org/apache/wink/example/helloworld/HelloWorldTest.java new file mode 100644 index 0000000000..ed121ffe29 --- /dev/null +++ b/collaboration/wink-helloworld-sca/src/test/java/org/apache/wink/example/helloworld/HelloWorldTest.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *******************************************************************************/ + +package org.apache.wink.example.helloworld; + +import java.io.FileNotFoundException; +import java.io.StringReader; +import java.util.Set; + +import org.apache.wink.common.http.HttpStatus; +import org.apache.wink.common.internal.application.ApplicationFileLoader; +import org.apache.wink.common.internal.utils.MediaTypeUtils; +import org.apache.wink.common.model.atom.AtomEntry; +import org.apache.wink.server.internal.servlet.MockServletInvocationTest; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +/** + * Test of response from HelloWorld Resource. + */ +public class HelloWorldTest extends MockServletInvocationTest { + + @Override + protected Class<?>[] getClasses() { + try { + Set<Class<?>> classes = new ApplicationFileLoader("application").getClasses(); + Class<?>[] classesArray = new Class[classes.size()]; + return classes.toArray(classesArray); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + public void testHelloWorld() throws Exception { + // prepare a mock request and an empty mock response + MockHttpServletRequest request = + constructMockRequest("GET", "/world", MediaTypeUtils.ATOM_ENTRY); + MockHttpServletResponse response = invoke(request); + + // check resulting mock response + assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); + AtomEntry entry = AtomEntry.unmarshal(new StringReader(response.getContentAsString())); + String id = entry.getId(); + assertEquals("entry id", HelloWorld.ID, id); + } + + // test helper + private MockHttpServletRequest constructMockRequest(String method, + String requestURI, + String acceptHeader) { + MockHttpServletRequest mockRequest = new MockHttpServletRequest() { + + public String getPathTranslated() { + return null; // prevent Spring to resolve the file on the + // filesystem which fails + } + + }; + mockRequest.setMethod(method); + mockRequest.setRequestURI(requestURI); + mockRequest.addHeader("Accept", acceptHeader); + return mockRequest; + } +} |