You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/24 14:42:31 UTC
[04/51] [partial] Refactored project structure
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
deleted file mode 100644
index f13d8a4..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*******************************************************************************
- * 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.olingo.odata2.core.debug;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.HttpHeaders;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataMessageException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataContext.RuntimeMeasurement;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.apache.olingo.odata2.testutil.helper.StringHelper;
-import org.junit.Test;
-
-/**
- * Tests for the debug information output.
- *
- */
-public class ODataDebugResponseWrapperTest extends BaseTest {
-
- private static final String EXPECTED = "{"
- + "\"request\":{\"method\":\"GET\",\"uri\":\"http://test/entity\"},"
- + "\"response\":{\"status\":{\"code\":200,\"info\":\"OK\"}}}";
-
- private ODataContext mockContext(final ODataHttpMethod method) throws ODataException {
- ODataContext context = mock(ODataContext.class);
- when(context.getHttpMethod()).thenReturn(method.name());
- PathInfo pathInfo = mock(PathInfo.class);
- when(pathInfo.getRequestUri()).thenReturn(URI.create("http://test/entity"));
- when(context.getPathInfo()).thenReturn(pathInfo);
- when(context.getRuntimeMeasurements()).thenReturn(null);
- return context;
- }
-
- private ODataResponse mockResponse(final HttpStatusCodes status, final String body, final String contentType) {
- ODataResponse response = mock(ODataResponse.class);
- when(response.getStatus()).thenReturn(status);
- when(response.getEntity()).thenReturn(body);
- if (contentType != null) {
- when(response.getHeaderNames()).thenReturn(new HashSet<String>(Arrays.asList(HttpHeaders.CONTENT_TYPE)));
- when(response.getHeader(HttpHeaders.CONTENT_TYPE)).thenReturn(contentType);
- when(response.getContentHeader()).thenReturn(contentType);
- }
- return response;
- }
-
- private RuntimeMeasurement mockRuntimeMeasurement(final String method, final long startTime, final long stopTime,
- final long startMemory, final long stopMemory) {
- RuntimeMeasurement measurement = mock(RuntimeMeasurement.class);
- when(measurement.getClassName()).thenReturn("class");
- when(measurement.getMethodName()).thenReturn(method);
- when(measurement.getTimeStarted()).thenReturn(startTime);
- when(measurement.getTimeStopped()).thenReturn(stopTime);
- when(measurement.getMemoryStarted()).thenReturn(startMemory);
- when(measurement.getMemoryStopped()).thenReturn(stopMemory);
- return measurement;
- }
-
- private RuntimeMeasurement mockRuntimeMeasurement(final String method, final long start, final long stop) {
- return mockRuntimeMeasurement(method, start, stop, 1000, 4000);
- }
-
- @Test
- public void minimal() throws Exception {
- final ODataContext context = mockContext(ODataHttpMethod.PUT);
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.NO_CONTENT, null, null);
-
- final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String actualJson = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace(ODataHttpMethod.GET.name(), ODataHttpMethod.PUT.name())
- .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
- Integer.toString(HttpStatusCodes.NO_CONTENT.getStatusCode()))
- .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.NO_CONTENT.getInfo()),
- actualJson);
- }
-
- @Test
- public void body() throws Exception {
- final ODataContext context = mockContext(ODataHttpMethod.GET);
- ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, "\"test\"", HttpContentType.APPLICATION_JSON);
-
- ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("{\"request", "{\"body\":\"test\",\"request")
- .replace("}}}",
- "},\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.APPLICATION_JSON + "\"}}}"),
- entity);
-
- wrappedResponse = mockResponse(HttpStatusCodes.OK, "test", HttpContentType.TEXT_PLAIN);
- response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(
- EXPECTED.replace("{\"request", "{\"body\":\"test\",\"request")
- .replace("}}}",
- "},\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.TEXT_PLAIN + "\"}}}"),
- entity);
-
- wrappedResponse = mockResponse(HttpStatusCodes.OK, null, "image/png");
- when(wrappedResponse.getEntity()).thenReturn(new ByteArrayInputStream("test".getBytes()));
- response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("{\"request", "{\"body\":\"dGVzdA==\",\"request")
- .replace("}}}", "},\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"image/png\"}}}"),
- entity);
- }
-
- @Test
- public void headers() throws Exception {
- ODataContext context = mockContext(ODataHttpMethod.GET);
- Map<String, List<String>> headers = new HashMap<String, List<String>>();
- headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(HttpContentType.APPLICATION_JSON));
- when(context.getRequestHeaders()).thenReturn(headers);
-
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, HttpContentType.APPLICATION_JSON);
-
- final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("},\"response",
- ",\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.APPLICATION_JSON + "\"}},\"response")
- .replace("}}}",
- "},\"headers\":{\"" + HttpHeaders.CONTENT_TYPE + "\":\"" + HttpContentType.APPLICATION_JSON + "\"}}}"),
- entity);
- }
-
- @Test
- public void uri() throws Exception {
- final ODataContext context = mockContext(ODataHttpMethod.GET);
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
-
- UriInfo uriInfo = mock(UriInfo.class);
- final FilterExpression filter = UriParser.parseFilter(null, null, "true");
- when(uriInfo.getFilter()).thenReturn(filter);
- final OrderByExpression orderBy = UriParser.parseOrderBy(null, null, "true");
- when(uriInfo.getOrderBy()).thenReturn(orderBy);
- List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>();
- NavigationPropertySegment segment = mock(NavigationPropertySegment.class);
- EdmNavigationProperty navigationProperty = mock(EdmNavigationProperty.class);
- when(navigationProperty.getName()).thenReturn("nav");
- when(segment.getNavigationProperty()).thenReturn(navigationProperty);
- ArrayList<NavigationPropertySegment> segments = new ArrayList<NavigationPropertySegment>();
- segments.add(segment);
- expand.add(segments);
- when(uriInfo.getExpand()).thenReturn(expand);
- SelectItem select1 = mock(SelectItem.class);
- SelectItem select2 = mock(SelectItem.class);
- EdmProperty property = mock(EdmProperty.class);
- when(property.getName()).thenReturn("property");
- when(select1.getProperty()).thenReturn(property);
- when(select2.getProperty()).thenReturn(property);
- when(select2.getNavigationPropertySegments()).thenReturn(segments);
- when(uriInfo.getSelect()).thenReturn(Arrays.asList(select1, select2));
-
- final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("}}}",
- "}},\"uri\":{\"filter\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"},"
- + "\"orderby\":{\"nodeType\":\"order collection\","
- + "\"orders\":[{\"nodeType\":\"ORDER\",\"sortorder\":\"asc\","
- + "\"expression\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"}}]},"
- + "\"expand/select\":{\"all\":false,\"properties\":[\"property\"],"
- + "\"links\":[{\"nav\":{\"all\":false,\"properties\":[\"property\"],\"links\":[]}}]}}}"),
- entity);
- }
-
- @Test
- public void uriWithException() throws Exception {
- final ODataContext context = mockContext(ODataHttpMethod.GET);
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
-
- UriInfo uriInfo = mock(UriInfo.class);
- FilterExpression filter = mock(FilterExpression.class);
- when(filter.getExpressionString()).thenReturn("wrong");
- when(uriInfo.getFilter()).thenReturn(filter);
- ExpressionParserException exception = mock(ExpressionParserException.class);
- when(exception.getMessageReference()).thenReturn(ExpressionParserException.COMMON_ERROR);
- when(exception.getStackTrace()).thenReturn(new StackTraceElement[] {
- new StackTraceElement("class", "method", "file", 42) });
- CommonExpression filterTree = mock(CommonExpression.class);
- when(filterTree.getUriLiteral()).thenReturn("wrong");
- when(exception.getFilterTree()).thenReturn(filterTree);
-
- final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, exception,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("}}}",
- "}},\"uri\":{\"error\":{\"filter\":\"wrong\"},\"filter\":null},"
- + "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
- + "\"message\":\"Error while parsing a ODATA expression.\","
- + "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}}],"
- + "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42}]}}"),
- entity);
- }
-
- @Test
- public void runtime() throws Exception {
- ODataContext context = mockContext(ODataHttpMethod.GET);
- List<RuntimeMeasurement> runtimeMeasurements = new ArrayList<RuntimeMeasurement>();
- runtimeMeasurements.add(mockRuntimeMeasurement("method", 1000, 42000));
- runtimeMeasurements.add(mockRuntimeMeasurement("inner", 2000, 5000));
- runtimeMeasurements.add(mockRuntimeMeasurement("inner", 7000, 12000));
- runtimeMeasurements.add(mockRuntimeMeasurement("inner", 13000, 16000));
- runtimeMeasurements.add(mockRuntimeMeasurement("inner2", 14000, 15000));
- runtimeMeasurements.add(mockRuntimeMeasurement("child", 17000, 21000));
- runtimeMeasurements.add(mockRuntimeMeasurement("second", 45000, 99000));
- when(context.getRuntimeMeasurements()).thenReturn(runtimeMeasurements);
-
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
-
- ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED.replace("}}}",
- "}},\"runtime\":[{\"class\":\"class\",\"method\":\"method\",\"duration\":41,\"memory\":3,"
- + "\"children\":[{\"class\":\"class\",\"method\":\"inner\",\"duration\":8,\"memory\":6,\"children\":[]},"
- + "{\"class\":\"class\",\"method\":\"inner\",\"duration\":3,\"memory\":3,\"children\":["
- + "{\"class\":\"class\",\"method\":\"inner2\",\"duration\":1,\"memory\":3,\"children\":[]}]},"
- + "{\"class\":\"class\",\"method\":\"child\",\"duration\":4,\"memory\":3,\"children\":[]}]},"
- + "{\"class\":\"class\",\"method\":\"second\",\"duration\":54,\"memory\":3,\"children\":[]}]}"),
- entity);
- }
-
- @Test
- public void exception() throws Exception {
- final ODataContext context = mockContext(ODataHttpMethod.GET);
- final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.BAD_REQUEST, null, null);
-
- ODataMessageException exception = mock(ODataMessageException.class);
- when(exception.getMessageReference()).thenReturn(ODataMessageException.COMMON);
- RuntimeException innerException = mock(RuntimeException.class);
- when(innerException.getLocalizedMessage()).thenReturn("error");
- final StackTraceElement[] stackTrace = new StackTraceElement[] {
- new StackTraceElement("innerClass", "innerMethod", "innerFile", 99),
- new StackTraceElement("class", "method", "file", 42),
- new StackTraceElement("outerClass", "outerMethod", "outerFile", 11) };
- when(innerException.getStackTrace()).thenReturn(stackTrace);
- when(exception.getCause()).thenReturn(innerException);
- when(exception.getStackTrace()).thenReturn(Arrays.copyOfRange(stackTrace, 1, 3));
-
- final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
- String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
- assertEquals(EXPECTED
- .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
- Integer.toString(HttpStatusCodes.BAD_REQUEST.getStatusCode()))
- .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.BAD_REQUEST.getInfo())
- .replace("}}}", "}},"
- + "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
- + "\"message\":\"Common exception\","
- + "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}},"
- + "{\"class\":\"" + innerException.getClass().getName() + "\",\"message\":\"error\","
- + "\"invocation\":{\"class\":\"innerClass\",\"method\":\"innerMethod\",\"line\":99}}],"
- + "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42},"
- + "{\"class\":\"outerClass\",\"method\":\"outerMethod\",\"line\":11}]}}"),
- entity);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmImplTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmImplTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmImplTest.java
deleted file mode 100644
index 8d2cfa3..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmImplTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * 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.olingo.odata2.core.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
- */
-public class EdmImplTest extends BaseTest {
-
- private ForEdmImplTest edm;
-
- @Before
- public void getEdmImpl() throws EdmException {
- edm = new ForEdmImplTest();
- }
-
- @Test
- public void testEntityContainerCache() throws EdmException {
- assertEquals(edm.getEntityContainer("foo"), edm.getEntityContainer("foo"));
- assertNotSame(edm.getEntityContainer("foo"), edm.getEntityContainer("bar"));
- assertEquals(edm.getDefaultEntityContainer(), edm.getEntityContainer(null));
- assertNotSame(edm.getDefaultEntityContainer(), edm.getEntityContainer(""));
- }
-
- @Test
- public void testEntityTypeCache() throws EdmException {
- assertEquals(edm.getEntityType("foo", "bar"), edm.getEntityType("foo", "bar"));
- assertNotSame(edm.getEntityType("foo", "bar"), edm.getEntityType("bar", "foo"));
- }
-
- @Test
- public void testComplexTypeCache() throws EdmException {
- assertEquals(edm.getComplexType("foo", "bar"), edm.getComplexType("foo", "bar"));
- assertNotSame(edm.getComplexType("foo", "bar"), edm.getComplexType("bar", "foo"));
- }
-
- @Test
- public void testAssociationCache() throws EdmException {
- assertEquals(edm.getAssociation("foo", "bar"), edm.getAssociation("foo", "bar"));
- assertNotSame(edm.getAssociation("foo", "bar"), edm.getAssociation("bar", "foo"));
- }
-
- @Test
- public void testEntitySetsCache() throws EdmException {
- assertEquals(edm.getEntitySets(), edm.getEntitySets());
- }
-
- @Test
- public void testFunctionImportCache() throws EdmException {
- assertEquals(edm.getFunctionImports(), edm.getFunctionImports());
- }
-
- private class ForEdmImplTest extends EdmImpl {
-
- public ForEdmImplTest() {
- super(null);
- }
-
- @Override
- protected EdmEntityContainer createEntityContainer(final String name) throws ODataException {
- EdmEntityContainer edmEntityContainer = mock(EdmEntityContainer.class);
- when(edmEntityContainer.getName()).thenReturn(name);
- return edmEntityContainer;
- }
-
- @Override
- protected EdmEntityType createEntityType(final FullQualifiedName fqName) throws ODataException {
- EdmEntityType edmEntityType = mock(EdmEntityType.class);
- when(edmEntityType.getNamespace()).thenReturn(fqName.getNamespace());
- when(edmEntityType.getName()).thenReturn(fqName.getName());
- return edmEntityType;
- }
-
- @Override
- protected EdmComplexType createComplexType(final FullQualifiedName fqName) throws ODataException {
- EdmComplexType edmComplexType = mock(EdmComplexType.class);
- when(edmComplexType.getNamespace()).thenReturn(fqName.getNamespace());
- when(edmComplexType.getName()).thenReturn(fqName.getName());
- return edmComplexType;
- }
-
- @Override
- protected EdmAssociation createAssociation(final FullQualifiedName fqName) throws ODataException {
- EdmAssociation edmAssociation = mock(EdmAssociation.class);
- when(edmAssociation.getNamespace()).thenReturn(fqName.getNamespace());
- when(edmAssociation.getName()).thenReturn(fqName.getName());
- return edmAssociation;
- }
-
- @Override
- protected List<EdmEntitySet> createEntitySets() throws ODataException {
- List<EdmEntitySet> edmEntitySets = new ArrayList<EdmEntitySet>();
- return edmEntitySets;
- }
-
- @Override
- protected List<EdmFunctionImport> createFunctionImports() throws ODataException {
- List<EdmFunctionImport> edmFunctionImports = new ArrayList<EdmFunctionImport>();
- return edmFunctionImports;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeTest.java
deleted file mode 100644
index 39912ee..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeFacadeTest.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/*******************************************************************************
- * 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.olingo.odata2.core.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmLiteral;
-import org.apache.olingo.odata2.api.edm.EdmLiteralException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.exception.MessageReference;
-import org.apache.olingo.odata2.api.uri.UriSyntaxException;
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.junit.Test;
-
-/**
- * Tests for the parsing of URI literals
- *
- */
-public class EdmSimpleTypeFacadeTest extends BaseTest {
-
- public static void parse(final String literal, final EdmSimpleType expectedType) throws EdmLiteralException {
- final EdmLiteral uriLiteral = EdmSimpleTypeKind.parseUriLiteral(literal);
- assertNotNull(uriLiteral);
- if (!expectedType.equals(EdmNull.getInstance())) {
- assertNotNull(uriLiteral.getLiteral());
- assertTrue(uriLiteral.getLiteral().length() > 0);
- }
- assertNotNull(uriLiteral.getType());
- assertEquals(expectedType, uriLiteral.getType());
- }
-
- public static void compare(final EdmSimpleTypeKind simpleType) {
- final EdmSimpleType bin1 = simpleType.getEdmSimpleTypeInstance();
- assertNotNull(bin1);
-
- final EdmSimpleType bin2 = simpleType.getEdmSimpleTypeInstance();
- assertNotNull(bin2);
-
- assertEquals(bin1, bin2);
- }
-
- @Test
- public void parseUriLiteralBinary() throws EdmLiteralException {
- parse("X'Fa12aAA1'", EdmBinary.getInstance());
- parse("binary'FA12AAA1'", EdmBinary.getInstance());
- }
-
- @Test
- public void parseUriLiteralBoolean() throws EdmLiteralException {
- parse("true", EdmBoolean.getInstance());
- parse("false", EdmBoolean.getInstance());
- }
-
- @Test
- public void parseUriLiteralBit() throws EdmLiteralException {
- parse("1", Bit.getInstance());
- parse("0", Bit.getInstance());
- }
-
- @Test
- public void parseUriLiteralByte() throws EdmLiteralException {
- parse("255", EdmByte.getInstance());
- }
-
- @Test
- public void parseUriLiteralUint7() throws EdmLiteralException {
- parse("123", Uint7.getInstance());
- parse("111", Uint7.getInstance());
- parse("42", Uint7.getInstance());
- }
-
- @Test
- public void parseUriLiteralDateTime() throws EdmLiteralException {
- parse("datetime'2009-12-26T21:23:38'", EdmDateTime.getInstance());
- }
-
- @Test
- public void parseUriLiteralDateTimeOffset() throws EdmLiteralException {
- parse("datetimeoffset'2009-12-26T21:23:38Z'", EdmDateTimeOffset.getInstance());
- parse("datetimeoffset'2002-10-10T12:00:00-05:00'", EdmDateTimeOffset.getInstance());
- parse("datetimeoffset'2009-12-26T21:23:38'", EdmDateTimeOffset.getInstance());
- }
-
- @Test
- public void parseUriLiteralDecimal() throws EdmLiteralException {
- parse("4.5m", EdmDecimal.getInstance());
- parse("4.5M", EdmDecimal.getInstance());
- }
-
- @Test
- public void parseUriLiteralDouble() throws EdmLiteralException {
- parse("4.5d", EdmDouble.getInstance());
- parse("4.5D", EdmDouble.getInstance());
- }
-
- @Test
- public void parseUriLiteralGuid() throws EdmLiteralException {
- parse("guid'1225c695-cfb8-4ebb-aaaa-80da344efa6a'", EdmGuid.getInstance());
- }
-
- @Test
- public void parseUriLiteralInt16() throws EdmLiteralException {
- parse("-32768", EdmInt16.getInstance());
- parse("3276", EdmInt16.getInstance());
- }
-
- @Test
- public void parseUriLiteralInt32() throws EdmLiteralException {
- parse("-327687", EdmInt32.getInstance());
- parse("32768", EdmInt32.getInstance());
- }
-
- @Test
- public void parseUriLiteralInt64() throws EdmLiteralException {
- parse("64l", EdmInt64.getInstance());
- parse("64L", EdmInt64.getInstance());
- }
-
- @Test
- public void parseUriLiteralNull() throws EdmLiteralException {
- parse(null, EdmNull.getInstance());
- parse("null", EdmNull.getInstance());
- }
-
- @Test
- public void parseUriLiteralSByte() throws EdmLiteralException {
- parse("-123", EdmSByte.getInstance());
- }
-
- @Test
- public void parseUriLiteralSingle() throws EdmLiteralException {
- parse("4.5f", EdmSingle.getInstance());
- parse("4.5F", EdmSingle.getInstance());
- parse("-INF", EdmSingle.getInstance());
- parse("INF", EdmSingle.getInstance());
- parse("NaN", EdmSingle.getInstance());
- }
-
- @Test
- public void parseUriLiteralString() throws EdmLiteralException {
- parse("'abc'", EdmString.getInstance());
- }
-
- @Test
- public void parseUriLiteralTime() throws EdmLiteralException {
- parse("time'PT120S'", EdmTime.getInstance());
- }
-
- @Test
- public void compareTypes() {
- compare(EdmSimpleTypeKind.Binary);
- compare(EdmSimpleTypeKind.Boolean);
- compare(EdmSimpleTypeKind.Byte);
- compare(EdmSimpleTypeKind.SByte);
- compare(EdmSimpleTypeKind.DateTime);
- compare(EdmSimpleTypeKind.DateTimeOffset);
- compare(EdmSimpleTypeKind.Decimal);
- compare(EdmSimpleTypeKind.Double);
- compare(EdmSimpleTypeKind.Guid);
- compare(EdmSimpleTypeKind.Int16);
- compare(EdmSimpleTypeKind.Int32);
- compare(EdmSimpleTypeKind.Int64);
- compare(EdmSimpleTypeKind.Single);
- compare(EdmSimpleTypeKind.Time);
- }
-
- /**
- * Parse a URI literal value string and assert that it is compatible
- * to the given EDM simple type and has the correct parsed value.
- *
- * @param literal
- * the URI literal value to be parsed as string
- * @param typeKind
- * the {@link EdmSimpleTypeKind} the URI literal should be compatible to
- * @param expectedLiteral
- * the expected literal value
- * @throws UriSyntaxException
- * @throws EdmException
- */
- private void parseLiteral(final String literal, final EdmSimpleTypeKind typeKind, final String expectedLiteral)
- throws UriSyntaxException, EdmException {
- final EdmLiteral uriLiteral = EdmSimpleTypeKind.parseUriLiteral(literal);
-
- assertTrue(typeKind.getEdmSimpleTypeInstance().isCompatible(uriLiteral.getType()));
- assertEquals(expectedLiteral, uriLiteral.getLiteral());
- }
-
- @Test
- public void parseDecimal() throws Exception {
- parseLiteral("4.5m", EdmSimpleTypeKind.Decimal, "4.5");
- parseLiteral("4.5M", EdmSimpleTypeKind.Decimal, "4.5");
- parseLiteral("1", EdmSimpleTypeKind.Decimal, "1");
- parseLiteral("255", EdmSimpleTypeKind.Decimal, "255");
- parseLiteral("-32768", EdmSimpleTypeKind.Decimal, "-32768");
- parseLiteral("32768", EdmSimpleTypeKind.Decimal, "32768");
- parseLiteral("3000000", EdmSimpleTypeKind.Decimal, "3000000");
- parseLiteral("4.5d", EdmSimpleTypeKind.Decimal, "4.5");
- parseLiteral("4.2E9F", EdmSimpleTypeKind.Decimal, "4.2E9");
- parseLiteral("1234567890", EdmSimpleTypeKind.Decimal, "1234567890");
- }
-
- @Test
- public void parseInt16() throws Exception {
- parseLiteral("16", EdmSimpleTypeKind.Int16, "16");
- parseLiteral("-16", EdmSimpleTypeKind.Int16, "-16");
- parseLiteral("255", EdmSimpleTypeKind.Int16, "255");
- parseLiteral("-32768", EdmSimpleTypeKind.Int16, "-32768");
-
- }
-
- @Test
- public void parseInt32() throws Exception {
- parseLiteral("32", EdmSimpleTypeKind.Int32, "32");
- parseLiteral("-127", EdmSimpleTypeKind.Int32, "-127");
- parseLiteral("255", EdmSimpleTypeKind.Int32, "255");
- parseLiteral("32767", EdmSimpleTypeKind.Int32, "32767");
- parseLiteral("-32769", EdmSimpleTypeKind.Int32, "-32769");
- }
-
- @Test
- public void parseInt64() throws Exception {
- parseLiteral("64", EdmSimpleTypeKind.Int64, "64");
- parseLiteral("255", EdmSimpleTypeKind.Int64, "255");
- parseLiteral("1000", EdmSimpleTypeKind.Int64, "1000");
- parseLiteral("100000", EdmSimpleTypeKind.Int64, "100000");
- parseLiteral("-64L", EdmSimpleTypeKind.Int64, "-64");
- parseLiteral("" + Long.MAX_VALUE + "L", EdmSimpleTypeKind.Int64, "" + Long.MAX_VALUE);
- parseLiteral("" + Long.MIN_VALUE + "l", EdmSimpleTypeKind.Int64, "" + Long.MIN_VALUE);
- }
-
- @Test
- public void parseString() throws Exception {
- parseLiteral("'abc'", EdmSimpleTypeKind.String, "abc");
- parseLiteral("'true'", EdmSimpleTypeKind.String, "true");
- parseLiteral("''", EdmSimpleTypeKind.String, "");
- }
-
- @Test
- public void parseSingle() throws Exception {
- parseLiteral("45", EdmSimpleTypeKind.Single, "45");
- parseLiteral("255", EdmSimpleTypeKind.Single, "255");
- parseLiteral("-32768", EdmSimpleTypeKind.Single, "-32768");
- parseLiteral("32768", EdmSimpleTypeKind.Single, "32768");
- parseLiteral("1L", EdmSimpleTypeKind.Single, "1");
- parseLiteral("4.5f", EdmSimpleTypeKind.Single, "4.5");
- parseLiteral("4.5F", EdmSimpleTypeKind.Single, "4.5");
- parseLiteral("4.5e9f", EdmSimpleTypeKind.Single, "4.5e9");
- parseLiteral("-INF", EdmSimpleTypeKind.Single, "-INF");
- parseLiteral("INF", EdmSimpleTypeKind.Single, "INF");
- parseLiteral("NaN", EdmSimpleTypeKind.Single, "NaN");
- }
-
- @Test
- public void parseDouble() throws Exception {
- parseLiteral("45", EdmSimpleTypeKind.Double, "45");
- parseLiteral("255", EdmSimpleTypeKind.Double, "255");
- parseLiteral("-32768", EdmSimpleTypeKind.Double, "-32768");
- parseLiteral("32768", EdmSimpleTypeKind.Double, "32768");
- parseLiteral("1l", EdmSimpleTypeKind.Double, "1");
- parseLiteral("4.5d", EdmSimpleTypeKind.Double, "4.5");
- parseLiteral("4.5D", EdmSimpleTypeKind.Double, "4.5");
- parseLiteral("4.5e21f", EdmSimpleTypeKind.Double, "4.5e21");
- }
-
- @Test
- public void parseByte() throws Exception {
- parseLiteral("255", EdmSimpleTypeKind.Byte, "255");
- parseLiteral("123", EdmSimpleTypeKind.Byte, "123");
- }
-
- @Test
- public void parseGuid() throws Exception {
- parseLiteral("guid'1225c695-cfb8-4ebb-aaaa-80da344efa6a'", EdmSimpleTypeKind.Guid,
- "1225c695-cfb8-4ebb-aaaa-80da344efa6a");
- }
-
- @Test
- public void parseTime() throws Exception {
- parseLiteral("time'PT120S'", EdmSimpleTypeKind.Time, "PT120S");
- }
-
- @Test
- public void parseDatetime() throws Exception {
- parseLiteral("datetime'2009-12-26T21:23:38'", EdmSimpleTypeKind.DateTime, "2009-12-26T21:23:38");
- }
-
- @Test
- public void parseDatetimeOffset() throws Exception {
- parseLiteral("datetimeoffset'2009-12-26T21:23:38Z'", EdmSimpleTypeKind.DateTimeOffset, "2009-12-26T21:23:38Z");
- parseLiteral("datetimeoffset'2002-10-10T12:00:00-05:00'", EdmSimpleTypeKind.DateTimeOffset,
- "2002-10-10T12:00:00-05:00");
- parseLiteral("datetimeoffset'2009-12-26T21:23:38'", EdmSimpleTypeKind.DateTimeOffset, "2009-12-26T21:23:38");
- }
-
- @Test
- public void parseBoolean() throws Exception {
- parseLiteral("true", EdmSimpleTypeKind.Boolean, "true");
- parseLiteral("false", EdmSimpleTypeKind.Boolean, "false");
- parseLiteral("1", EdmSimpleTypeKind.Boolean, "1");
- parseLiteral("0", EdmSimpleTypeKind.Boolean, "0");
- }
-
- @Test
- public void parseSByte() throws Exception {
- parseLiteral("-123", EdmSimpleTypeKind.SByte, "-123");
- parseLiteral("12", EdmSimpleTypeKind.SByte, "12");
- }
-
- @Test
- public void parseBinary() throws Exception {
- parseLiteral("X'Fa12aAA1'", EdmSimpleTypeKind.Binary, "+hKqoQ==");
- parseLiteral("binary'FA12AAA1'", EdmSimpleTypeKind.Binary, "+hKqoQ==");
- }
-
- private void parseWrongLiteralContent(final String literal, final MessageReference messageReference) {
- try {
- EdmSimpleTypeKind.parseUriLiteral(literal);
- fail("Expected EdmLiteralException not thrown");
- } catch (EdmLiteralException e) {
- assertNotNull(e);
- assertEquals(messageReference.getKey(), e.getMessageReference().getKey());
- }
- }
-
- @Test
- public void parseLiteralWithWrongContent() throws Exception {
- parseWrongLiteralContent("binary'abcde'", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("'", EdmLiteralException.UNKNOWNLITERAL);
- parseWrongLiteralContent("'a", EdmLiteralException.UNKNOWNLITERAL);
- parseWrongLiteralContent("wrongprefix'PT1H2M3S'", EdmLiteralException.UNKNOWNLITERAL);
- parseWrongLiteralContent("32i", EdmLiteralException.UNKNOWNLITERAL);
- parseWrongLiteralContent("9876543210", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("-9876543210", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("12345678901234567890L", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("12345678901234567890D", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("1234567890F", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("guid'a'", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("datetime'1'", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("datetimeoffset'2'", EdmLiteralException.LITERALFORMAT);
- parseWrongLiteralContent("time'3'", EdmLiteralException.LITERALFORMAT);
- }
-
- private void parseIncompatibleLiteralContent(final String literal, final EdmSimpleTypeKind typeKind)
- throws EdmLiteralException {
- final EdmLiteral uriLiteral = EdmSimpleTypeKind.parseUriLiteral(literal);
- assertFalse(typeKind.getEdmSimpleTypeInstance().isCompatible(uriLiteral.getType()));
- }
-
- @Test
- public void parseIncompatibleLiteral() throws Exception {
- parseIncompatibleLiteralContent("1D", EdmSimpleTypeKind.Binary);
- parseIncompatibleLiteralContent("'0'", EdmSimpleTypeKind.Boolean);
- parseIncompatibleLiteralContent("'1'", EdmSimpleTypeKind.Boolean);
- parseIncompatibleLiteralContent("2", EdmSimpleTypeKind.Boolean);
- parseIncompatibleLiteralContent("-1", EdmSimpleTypeKind.Byte);
- parseIncompatibleLiteralContent("-129", EdmSimpleTypeKind.Byte);
- parseIncompatibleLiteralContent("time'PT11H12M13S'", EdmSimpleTypeKind.DateTime);
- parseIncompatibleLiteralContent("time'PT11H12M13S'", EdmSimpleTypeKind.DateTimeOffset);
- parseIncompatibleLiteralContent("'1'", EdmSimpleTypeKind.Decimal);
- parseIncompatibleLiteralContent("1M", EdmSimpleTypeKind.Double);
- parseIncompatibleLiteralContent("1", EdmSimpleTypeKind.Guid);
- parseIncompatibleLiteralContent("32768", EdmSimpleTypeKind.Int16);
- parseIncompatibleLiteralContent("1L", EdmSimpleTypeKind.Int32);
- parseIncompatibleLiteralContent("1M", EdmSimpleTypeKind.Int64);
- parseIncompatibleLiteralContent("128", EdmSimpleTypeKind.SByte);
- parseIncompatibleLiteralContent("1D", EdmSimpleTypeKind.Single);
- parseIncompatibleLiteralContent("1", EdmSimpleTypeKind.String);
- parseIncompatibleLiteralContent("datetime'2012-10-10T11:12:13'", EdmSimpleTypeKind.Time);
- }
-}