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 2015/02/17 10:53:32 UTC
[18/35] olingo-odata4 git commit: [OLINGO-575] Removed V4 server code
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndingsTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndingsTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndingsTest.java
deleted file mode 100644
index efc3714..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndingsTest.java
+++ /dev/null
@@ -1,481 +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.server.core.deserializer.batch;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStreamReader;
-import java.util.List;
-
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
-import org.apache.olingo.server.core.deserializer.batch.Line;
-import org.junit.Test;
-
-public class BufferedReaderIncludingLineEndingsTest {
-
-
- private static final String TEXT_COMBINED = "Test\r" +
- "Test2\r\n" +
- "Test3\n" +
- "Test4\r" +
- "\r" +
- "\r\n" +
- "\r\n" +
- "Test5\n" +
- "Test6\r\n" +
- "Test7\n" +
- "\n";
-
- private static final String TEXT_SMALL = "Test\r" +
- "123";
- private static final String TEXT_EMPTY = "";
-
- @Test
- public void testSimpleText() throws Exception {
- final String TEXT = "Test";
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals(TEXT, reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testNoText() throws Exception {
- final String TEXT = "";
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testNoBytes() throws Exception {
- BufferedReaderIncludingLineEndings reader =
- new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(new byte[0])));
-
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testCRLF() throws Exception {
- final String TEXT = "Test\r\n" +
- "Test2";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals("Test\r\n", reader.readLine());
- assertEquals("Test2", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testLF() throws Exception {
- final String TEXT = "Test\n" +
- "Test2";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals("Test\n", reader.readLine());
- assertEquals("Test2", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testCR() throws Exception {
- final String TEXT = "Test\r" +
- "Test2";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals("Test2", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testCombined() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals("Test2\r\n", reader.readLine());
- assertEquals("Test3\n", reader.readLine());
- assertEquals("Test4\r", reader.readLine());
- assertEquals("\r", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("Test5\n", reader.readLine());
- assertEquals("Test6\r\n", reader.readLine());
- assertEquals("Test7\n", reader.readLine());
- assertEquals("\n", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testCombinedBufferSizeTwo() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED, 2);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals("Test2\r\n", reader.readLine());
- assertEquals("Test3\n", reader.readLine());
- assertEquals("Test4\r", reader.readLine());
- assertEquals("\r", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("Test5\n", reader.readLine());
- assertEquals("Test6\r\n", reader.readLine());
- assertEquals("Test7\n", reader.readLine());
- assertEquals("\n", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testCombinedBufferSizeOne() throws Exception {
- final String TEXT = "Test\r" +
- "Test2\r\n" +
- "Test3\n" +
- "Test4\r" +
- "\r" +
- "\r\n" +
- "\r\n" +
- "Test5\n" +
- "Test6\r\n" +
- "Test7\n" +
- "\r\n";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT, 1);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals("Test2\r\n", reader.readLine());
- assertEquals("Test3\n", reader.readLine());
- assertEquals("Test4\r", reader.readLine());
- assertEquals("\r", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertEquals("Test5\n", reader.readLine());
- assertEquals("Test6\r\n", reader.readLine());
- assertEquals("Test7\n", reader.readLine());
- assertEquals("\r\n", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
-
- reader.close();
- }
-
- @Test
- public void testDoubleLF() throws Exception {
- final String TEXT = "Test\r" +
- "\r";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT, 1);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals("\r", reader.readLine());
- reader.close();
- }
-
- @Test
- public void testSkipSimple() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
-
- assertEquals(5, reader.skip(5)); // Test\r
- assertEquals("123", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testSkipBufferOne() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
-
- assertEquals(5, reader.skip(5)); // Test\r
- assertEquals("123", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testReadThanSkip() throws Exception {
- final String TEXT = "Test\r" +
- "\r" +
- "123";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals("Test\r", reader.readLine());
- assertEquals(1, reader.skip(1)); // Test\r
- assertEquals("123", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testReadMoreBufferCapacityThanCharacterAvailable() throws Exception {
- final String TEXT = "Foo";
- char[] buffer = new char[20];
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
- assertEquals(3, reader.read(buffer, 0, 20));
- assertEquals(-1, reader.read(buffer, 0, 20));
- reader.close();
-
- BufferedReaderIncludingLineEndings readerBufferOne = create(TEXT, 1);
- assertEquals(3, readerBufferOne.read(buffer, 0, 20));
- assertEquals(-1, readerBufferOne.read(buffer, 0, 20));
- readerBufferOne.close();
- }
-
- @Test
- public void testSkipZero() throws Exception {
- final String TEXT = "Test\r" +
- "123\r\n";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals(0, reader.skip(0)); // Test\r
- assertEquals("Test\r", reader.readLine());
- assertEquals("123\r\n", reader.readLine());
- assertNull(reader.readLine());
- assertNull(reader.readLine());
- reader.close();
- }
-
- @Test
- public void testSkipToMuch() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
-
- assertEquals(8, reader.skip(10)); // Test\r
- assertEquals(null, reader.readLine());
- reader.close();
- }
-
- @Test
- public void testReadBufferOne() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
-
- assertEquals('T', reader.read());
- assertEquals('e', reader.read());
- assertEquals('s', reader.read());
- assertEquals('t', reader.read());
- assertEquals('\r', reader.read());
- assertEquals('1', reader.read());
- assertEquals('2', reader.read());
- assertEquals('3', reader.read());
- assertEquals(-1, reader.read());
- assertEquals(-1, reader.read());
- }
-
- @Test
- public void testReadZeroBytes() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
-
- char[] buffer = new char[3];
- assertEquals(0, reader.read(buffer, 0, 0));
- assertEquals('T', reader.read());
- assertEquals(0, reader.read(buffer, 0, 0));
- assertEquals("est\r", reader.readLine());
- assertEquals("123", reader.readLine());
-
- reader.close();
- }
-
- @Test
- public void testRead() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
-
- assertEquals('T', reader.read());
- assertEquals('e', reader.read());
- assertEquals('s', reader.read());
- assertEquals('t', reader.read());
- assertEquals('\r', reader.read());
- assertEquals('1', reader.read());
- assertEquals('2', reader.read());
- assertEquals('3', reader.read());
- assertEquals(-1, reader.read());
- assertEquals(-1, reader.read());
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testFailReadBufferAndOffsetBiggerThanBuffer() throws Exception {
- BufferedReaderIncludingLineEndings reader = create("");
-
- final char[] buffer = new char[3];
- reader.read(buffer, 1, 3);
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testFailLengthNegative() throws Exception {
- final char[] buffer = new char[3];
- BufferedReaderIncludingLineEndings reader = create("123");
-
- reader.read(buffer, 1, -2);
- reader.close();
- }
-
- @Test(expected = IndexOutOfBoundsException.class)
- public void testFailOffsetNegative() throws Exception {
- final char[] buffer = new char[3];
- BufferedReaderIncludingLineEndings reader = create("123");
-
- reader.read(buffer, -1, 2);
- reader.close();
- }
-
- @Test
- public void testReadAndReadLine() throws Exception {
- final String TEXT = "Test\r" +
- "bar\n" +
- "123\r\n" +
- "foo";
-
- BufferedReaderIncludingLineEndings reader = create(TEXT);
-
- assertEquals('T', reader.read());
- assertEquals('e', reader.read());
- assertEquals('s', reader.read());
- assertEquals('t', reader.read());
- assertEquals("\r", reader.readLine());
- assertEquals("bar\n", reader.readLine());
- assertEquals('1', reader.read());
- assertEquals('2', reader.read());
- assertEquals("3\r\n", reader.readLine());
- assertEquals("foo", reader.readLine());
- assertEquals(null, reader.readLine());
- assertEquals(-1, reader.read());
- }
-
- @Test
- public void testLineEqualsAndHashCode() {
- Line l1 = new Line("The first line", 1);
- Line l2 = new Line("The first line", 1);
- Line l3 = new Line("The second line", 2);
-
- assertEquals(l1, l2);
- assertFalse(l1.equals(l3));
- assertTrue(l1.hashCode() != l3.hashCode());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSkipNegative() throws Exception {
- BufferedReaderIncludingLineEndings reader = create("123");
- reader.skip(-1);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFailBufferSizeZero() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY, 0);
- reader.close();
- }
-
- @Test(expected = NullPointerException.class)
- public void testInputStreamIsNull() throws Exception {
- // Same behaviour like BufferedReader
- BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(null);
- reader.close();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFailBufferSizeNegative() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY, -1);
- reader.close();
- }
-
- @Test
- public void testMarkSupoorted() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY);
-
- assertEquals(false, reader.markSupported());
- reader.close();
- }
-
- @Test(expected = Exception.class)
- public void testFailMark() throws Exception {
- BufferedReaderIncludingLineEndings reader = create("123");
-
- reader.mark(1);
- }
-
- @Test(expected = Exception.class)
- public void testFailReset() throws Exception {
- BufferedReaderIncludingLineEndings reader = create("123");
-
- reader.reset();
- }
-
- @Test
- public void testReady() throws Exception {
- BufferedReaderIncludingLineEndings reader = create("123\r123");
- assertEquals(false, reader.ready());
- assertEquals("123\r", reader.readLine());
- assertEquals(true, reader.ready());
- assertEquals("123", reader.readLine());
- assertEquals(false, reader.ready());
-
- reader.close();
- }
-
- @Test
- public void testToList() throws Exception {
- BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED);
- List<Line> stringList = reader.toLineList();
-
- assertEquals(11, stringList.size());
- assertEquals("Test\r", stringList.get(0).toString());
- assertEquals("Test2\r\n", stringList.get(1).toString());
- assertEquals("Test3\n", stringList.get(2).toString());
- assertEquals("Test4\r", stringList.get(3).toString());
- assertEquals("\r", stringList.get(4).toString());
- assertEquals("\r\n", stringList.get(5).toString());
- assertEquals("\r\n", stringList.get(6).toString());
- assertEquals("Test5\n", stringList.get(7).toString());
- assertEquals("Test6\r\n", stringList.get(8).toString());
- assertEquals("Test7\n", stringList.get(9).toString());
- assertEquals("\n", stringList.get(10).toString());
- reader.close();
- }
-
- private BufferedReaderIncludingLineEndings create(final String inputString) throws Exception {
- return new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(inputString
- .getBytes("UTF-8"))));
- }
-
- private BufferedReaderIncludingLineEndings create(final String inputString, int bufferSize) throws Exception {
- return new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(inputString
- .getBytes("UTF-8"))), bufferSize);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java
deleted file mode 100644
index 282251e..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java
+++ /dev/null
@@ -1,171 +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.server.core.deserializer.batch;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.commons.api.http.HttpContentType;
-import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
-import org.apache.olingo.server.core.deserializer.batch.Header;
-import org.junit.Test;
-
-public class HeaderTest {
-
- @Test
- public void test() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
-
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(1, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
- }
-
- @Test
- public void testNotAvailable() {
- Header header = new Header(1);
-
- assertNull(header.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(0, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- assertEquals("", header.getHeaderNotNull(HttpHeader.CONTENT_TYPE));
- }
-
- @Test
- public void testCaseInsensitive() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
-
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeader("cOnTenT-TyPE"));
- assertEquals(1, header.getHeaders("cOnTenT-TyPE").size());
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders("cOnTenT-TyPE").get(0));
- }
-
- @Test
- public void testDuplicatedAdd() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 2);
-
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(1, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
- }
-
- @Test
- public void testMatcher() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=123", 1);
-
- assertTrue(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
- }
-
- @Test
- public void testFieldName() {
- Header header = new Header(0);
- header.addHeader("MyFieldNamE", "myValue", 1);
-
- assertEquals("MyFieldNamE", header.getHeaderField("myfieldname").getFieldName());
- assertEquals("MyFieldNamE", header.toSingleMap().keySet().toArray(new String[0])[0]);
- assertEquals("MyFieldNamE", header.toMultiMap().keySet().toArray(new String[0])[0]);
-
- assertEquals("myValue", header.toMultiMap().get("MyFieldNamE").get(0));
- assertEquals("myValue", header.toSingleMap().get("MyFieldNamE"));
- }
-
- @Test
- public void testDeepCopy() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=123", 1);
-
- Header copy = header.clone();
- assertEquals(header.getHeaders(HttpHeader.CONTENT_TYPE), copy.getHeaders(HttpHeader.CONTENT_TYPE));
- assertEquals(header.getHeader(HttpHeader.CONTENT_TYPE), copy.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(header.getHeaderField(HttpHeader.CONTENT_TYPE), copy.getHeaderField(HttpHeader.CONTENT_TYPE));
-
- assertTrue(header.getHeaders(HttpHeader.CONTENT_TYPE) != copy.getHeaders(HttpHeader.CONTENT_TYPE));
- assertTrue(header.getHeaderField(HttpHeader.CONTENT_TYPE) != copy.getHeaderField(HttpHeader.CONTENT_TYPE));
- }
-
- @Test
- public void testMatcherNoHeader() {
- Header header = new Header(1);
-
- assertFalse(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
- }
-
- @Test
- public void testDuplicatedAddList() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
- header.addHeader(HttpHeader.CONTENT_TYPE, Arrays.asList(new String[] { HttpContentType.MULTIPART_MIXED,
- HttpContentType.APPLICATION_ATOM_SVC }), 2);
-
- assertEquals(HttpContentType.MULTIPART_MIXED + ", " + HttpContentType.APPLICATION_ATOM_SVC, header
- .getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(2, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
- assertEquals(HttpContentType.APPLICATION_ATOM_SVC, header.getHeaders(HttpHeader.CONTENT_TYPE).get(1));
- }
-
- @Test
- public void testRemove() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
- header.removeHeader(HttpHeader.CONTENT_TYPE);
-
- assertNull(header.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(0, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- }
-
- @Test
- public void testMultipleValues() {
- Header header = new Header(1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_ATOM_SVC, 2);
- header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_ATOM_XML, 3);
-
- final String fullHeaderString =
- HttpContentType.MULTIPART_MIXED + ", " + HttpContentType.APPLICATION_ATOM_SVC + ", "
- + HttpContentType.APPLICATION_ATOM_XML;
-
- assertEquals(fullHeaderString, header.getHeader(HttpHeader.CONTENT_TYPE));
- assertEquals(3, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
- assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
- assertEquals(HttpContentType.APPLICATION_ATOM_SVC, header.getHeaders(HttpHeader.CONTENT_TYPE).get(1));
- assertEquals(HttpContentType.APPLICATION_ATOM_XML, header.getHeaders(HttpHeader.CONTENT_TYPE).get(2));
- }
-
- @Test
- public void testSplitValues() {
- final String values = "abc, def,123,77, 99, ysd";
- List<String> splittedValues = Header.splitValuesByComma(values);
-
- assertEquals(6, splittedValues.size());
- assertEquals("abc", splittedValues.get(0));
- assertEquals("def", splittedValues.get(1));
- assertEquals("123", splittedValues.get(2));
- assertEquals("77", splittedValues.get(3));
- assertEquals("99", splittedValues.get(4));
- assertEquals("ysd", splittedValues.get(5));
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java
deleted file mode 100644
index 5ea7cc8..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java
+++ /dev/null
@@ -1,108 +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.server.core.deserializer.batch;
-
-import static org.junit.Assert.*;
-
-import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
-import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
-import org.junit.Test;
-
-public class HttpRequestStatusLineTest {
-
- private static final String HTTP_VERSION = "HTTP/1.1";
- private static final String SPACE = " ";
- private String baseUri = "http://localhost/odata";
- private String serviceResolutionUri = "";
-
- @Test
- public void testAbsolute() throws BatchDeserializerException {
- final HttpRequestStatusLine line = parse("http://localhost/odata/Employee?$top=2");
- assertEquals("$top=2", line.getRawQueryPath());
- assertEquals("/Employee", line.getRawODataPath());
- assertEquals("http://localhost/odata/Employee?$top=2", line.getRawRequestUri());
- assertEquals(baseUri, line.getRawBaseUri());
- assertEquals(serviceResolutionUri, line.getRawServiceResolutionUri());
- }
-
- @Test
- public void testAbsoluteWithRelativePath() throws BatchDeserializerException {
- final HttpRequestStatusLine line = parse("http://localhost/odata/../../Employee?$top=2");
- assertEquals("/../../Employee", line.getRawODataPath());
- assertEquals("$top=2", line.getRawQueryPath());
- assertEquals("http://localhost/odata/../../Employee?$top=2", line.getRawRequestUri());
- assertEquals(baseUri, line.getRawBaseUri());
- assertEquals(serviceResolutionUri, line.getRawServiceResolutionUri());
- }
-
- @Test
- public void testRelativeWithDots() throws BatchDeserializerException {
- final HttpRequestStatusLine line = parse("../../Employee?$top=2");
- assertEquals("/../../Employee", line.getRawODataPath());
- assertEquals("$top=2", line.getRawQueryPath());
- assertEquals("http://localhost/odata/../../Employee?$top=2", line.getRawRequestUri());
- assertEquals(baseUri, line.getRawBaseUri());
- assertEquals(serviceResolutionUri, line.getRawServiceResolutionUri());
- }
-
- @Test
- public void testRelative() throws BatchDeserializerException {
- final HttpRequestStatusLine line = parse("Employee?$top=2");
- assertEquals("$top=2", line.getRawQueryPath());
- assertEquals("/Employee", line.getRawODataPath());
- assertEquals("http://localhost/odata/Employee?$top=2", line.getRawRequestUri());
- assertEquals(baseUri, line.getRawBaseUri());
- assertEquals(serviceResolutionUri, line.getRawServiceResolutionUri());
- }
-
- @Test
- public void testRelativeMultipleSegements() throws BatchDeserializerException {
- final HttpRequestStatusLine line = parse("Employee/Manager/EmployeeName?$top=2");
- assertEquals("$top=2", line.getRawQueryPath());
- assertEquals("/Employee/Manager/EmployeeName", line.getRawODataPath());
- assertEquals("http://localhost/odata/Employee/Manager/EmployeeName?$top=2", line.getRawRequestUri());
- assertEquals(baseUri, line.getRawBaseUri());
- assertEquals(serviceResolutionUri, line.getRawServiceResolutionUri());
- }
-
- @Test
- public void testOtherBaseUri() throws BatchDeserializerException {
- parseFail("http://otherhost/odata/Employee?$top=2", MessageKeys.INVALID_BASE_URI);
- }
-
- @Test
- public void testInvalidRelative() throws BatchDeserializerException {
- parseFail("/Employee?$top=2", MessageKeys.INVALID_URI);
- }
-
- HttpRequestStatusLine parse(final String uri) throws BatchDeserializerException {
- Line statusline = new Line(HttpMethod.GET.toString().toUpperCase() + SPACE + uri + SPACE + HTTP_VERSION, 0);
- return new HttpRequestStatusLine(statusline, baseUri, serviceResolutionUri);
- }
-
- void parseFail(final String uri, MessageKeys messageKey) {
- try {
- parse(uri);
- fail("Expceted exception");
- } catch (BatchDeserializerException e) {
- assertEquals(messageKey, e.getMessageKey());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
deleted file mode 100644
index f3e22ef..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
+++ /dev/null
@@ -1,44 +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.server.core.deserializer.json;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.server.api.OData;
-import org.apache.olingo.server.api.deserializer.ODataDeserializer;
-import org.junit.Test;
-
-public class ODataJsonDeserializerBasicTest {
-
- @Test
- public void checkSupportedJsonFormats() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
- assertNotNull(deserializer);
- deserializer = null;
-
- deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON_NO_METADATA);
- assertNotNull(deserializer);
- deserializer = null;
-
- deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON_FULL_METADATA);
- assertNotNull(deserializer);
- deserializer = null;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
deleted file mode 100644
index f48f05c..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
+++ /dev/null
@@ -1,156 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmSingleton;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.server.api.edm.provider.Action;
-import org.apache.olingo.server.api.edm.provider.EntitySetPath;
-import org.apache.olingo.server.api.edm.provider.Parameter;
-import org.apache.olingo.server.api.edm.provider.ReturnType;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmActionImplTest {
-
- private EdmAction actionImpl1;
- private EdmAction actionImpl2;
- private EdmAction actionImpl3;
-
- @Before
- public void setup() {
- EdmProviderImpl provider = mock(EdmProviderImpl.class);
- List<Parameter> parameters = new ArrayList<Parameter>();
- parameters.add(new Parameter().setName("Id").setType(new FullQualifiedName("namespace", "name")));
- FullQualifiedName action1Name = new FullQualifiedName("namespace", "action1");
- Action action1 = new Action().setName("action1").setBound(true).setParameters(parameters);
- actionImpl1 = EdmActionImpl.getInstance(provider, action1Name, action1);
-
- FullQualifiedName action2Name = new FullQualifiedName("namespace", "action2");
- FullQualifiedName returnTypeName = new FullQualifiedName("Edm", "String");
- ReturnType returnType = new ReturnType().setType(returnTypeName);
- Action action2 = new Action().setName("action2").setParameters(parameters).setReturnType(returnType);
- actionImpl2 = EdmActionImpl.getInstance(provider, action2Name, action2);
-
- FullQualifiedName action3Name = new FullQualifiedName("namespace", "action3");
- EntitySetPath entitySetPath = new EntitySetPath().setBindingParameter("Id").setPath("path");
- Action action3 =
- new Action().setName("action3").setParameters(parameters).setReturnType(returnType).setEntitySetPath(
- entitySetPath);
- actionImpl3 = EdmActionImpl.getInstance(provider, action3Name, action3);
- }
-
- @Test
- public void action1BasicMethodCalls() {
- assertTrue(actionImpl1.isBound());
- assertEquals(EdmTypeKind.ACTION, actionImpl1.getKind());
- assertNull(actionImpl1.getReturnType());
- // assertEquals("returnName", actionImpl1.getReturnType().getType().getName());
- assertNotNull(actionImpl1.getParameterNames());
-
- for (String name : actionImpl1.getParameterNames()) {
- EdmParameter parameter = actionImpl1.getParameter(name);
- assertNotNull(parameter);
- assertEquals(name, parameter.getName());
- }
-
- assertNull(actionImpl1.getReturnedEntitySet(null));
- assertNull(actionImpl1.getReturnedEntitySet(mock(EdmEntitySet.class)));
- }
-
- @Test
- public void action2BasicMethodCalls() {
- assertFalse(actionImpl2.isBound());
- assertEquals(EdmTypeKind.ACTION, actionImpl2.getKind());
- assertEquals("String", actionImpl2.getReturnType().getType().getName());
- assertNotNull(actionImpl2.getParameterNames());
-
- for (String name : actionImpl2.getParameterNames()) {
- EdmParameter parameter = actionImpl2.getParameter(name);
- assertNotNull(parameter);
- assertEquals(name, parameter.getName());
- }
-
- assertNull(actionImpl2.getReturnedEntitySet(null));
- assertNull(actionImpl2.getReturnedEntitySet(mock(EdmEntitySet.class)));
- }
-
- @Test
- public void action3BasicMethodCalls() {
- assertFalse(actionImpl3.isBound());
- assertEquals(EdmTypeKind.ACTION, actionImpl3.getKind());
- assertEquals("String", actionImpl3.getReturnType().getType().getName());
- assertNotNull(actionImpl3.getParameterNames());
-
- for (String name : actionImpl3.getParameterNames()) {
- EdmParameter parameter = actionImpl3.getParameter(name);
- assertNotNull(parameter);
- assertEquals(name, parameter.getName());
- }
-
- actionImpl3.getReturnedEntitySet(null);
- }
-
- @Test
- public void action3getReturnedEntitySetWithEntitySet() {
- EdmEntitySet set = mock(EdmEntitySet.class);
- when(set.getRelatedBindingTarget("path")).thenReturn(set);
-
- EdmEntitySet returnedEntitySet = actionImpl3.getReturnedEntitySet(set);
-
- assertEquals(set, returnedEntitySet);
- }
-
- @Test(expected = EdmException.class)
- public void action3getReturnedEntitySetWithNullReturn() {
- EdmEntitySet set = mock(EdmEntitySet.class);
- when(set.getRelatedBindingTarget("path")).thenReturn(null);
-
- actionImpl3.getReturnedEntitySet(set);
- fail();
- }
-
- @Test(expected = EdmException.class)
- public void action3getReturnedEntitySetWithSingleton() {
- EdmSingleton singleton = mock(EdmSingleton.class);
- EdmEntitySet set = mock(EdmEntitySet.class);
- when(set.getRelatedBindingTarget("path")).thenReturn(singleton);
-
- actionImpl3.getReturnedEntitySet(set);
- fail();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
deleted file mode 100644
index 1b4f82c..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
+++ /dev/null
@@ -1,103 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-import org.apache.olingo.server.api.edm.provider.ActionImport;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmActionImportImplTest {
-
- EdmEntityContainer container;
-
- EdmActionImport actionImport;
-
- private EdmAction action;
-
- private EdmEntitySet entitySet;
-
- @Before
- public void setup() {
- FullQualifiedName actionFqn = new FullQualifiedName("namespace", "actionName");
- FullQualifiedName entityContainerFqn = new FullQualifiedName("namespace", "containerName");
- Target target = new Target().setEntityContainer(entityContainerFqn).setTargetName("entitySetName");
- ActionImport providerActionImport =
- new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
-
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- container = mock(EdmEntityContainer.class);
- when(edm.getEntityContainer(entityContainerFqn)).thenReturn(container);
- action = mock(EdmAction.class);
- when(edm.getUnboundAction(actionFqn)).thenReturn(action);
-
- entitySet = mock(EdmEntitySet.class);
- when(container.getEntitySet("entitySetName")).thenReturn(entitySet);
- actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
- }
-
- @Test
- public void simpleActionTest() {
- assertEquals("actionImportName", actionImport.getName());
- assertTrue(container == actionImport.getEntityContainer());
- assertTrue(action == actionImport.getUnboundAction());
- }
-
- @Test
- public void getReturnedEntitySet() {
- EdmEntitySet returnedEntitySet = actionImport.getReturnedEntitySet();
- assertNotNull(returnedEntitySet);
- assertTrue(returnedEntitySet == entitySet);
-
- // Chaching
- assertTrue(returnedEntitySet == actionImport.getReturnedEntitySet());
- }
-
- @Test(expected = EdmException.class)
- public void getReturnedEntitySetNonExistingContainer() {
- Target target = new Target();
- ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
- EdmActionImport actionImport =
- new EdmActionImportImpl(mock(EdmProviderImpl.class), container, providerActionImport);
- actionImport.getReturnedEntitySet();
- }
-
- @Test(expected = EdmException.class)
- public void getReturnedEntitySetNonExistingEntitySet() {
- Target target = new Target();
- ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- when(edm.getEntityContainer(null)).thenReturn(container);
- EdmActionImport actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
- actionImport.getReturnedEntitySet();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
deleted file mode 100644
index 8a66230..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
+++ /dev/null
@@ -1,166 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmElement;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.server.api.edm.provider.ComplexType;
-import org.apache.olingo.server.api.edm.provider.EdmProvider;
-import org.apache.olingo.server.api.edm.provider.NavigationProperty;
-import org.apache.olingo.server.api.edm.provider.Property;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmComplexTypeImplTest {
-
- private EdmComplexType baseType;
-
- private EdmComplexType type;
-
- @Before
- public void setupTypes() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
- ComplexType baseComplexType = new ComplexType();
- List<Property> baseProperties = new ArrayList<Property>();
- baseProperties.add(new Property().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- List<NavigationProperty> baseNavigationProperties = new ArrayList<NavigationProperty>();
- baseNavigationProperties.add(new NavigationProperty().setName("nav1"));
- baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
- .setNavigationProperties(baseNavigationProperties);
- when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
-
- baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType);
-
- FullQualifiedName name = new FullQualifiedName("namespace", "typeName");
- ComplexType complexType = new ComplexType().setBaseType(baseName);
- List<Property> properties = new ArrayList<Property>();
- properties.add(new Property().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("nav2"));
- complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties)
- .setNavigationProperties(navigationProperties);
- when(provider.getComplexType(name)).thenReturn(complexType);
-
- type = EdmComplexTypeImpl.getInstance(edm, name, complexType);
- }
-
- @Test
- public void noPropertiesAndNoNavPropertiesMustNotResultInException() {
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- ComplexType complexType = new ComplexType().setName("n");
- EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), complexType);
- }
-
- @Test
- public void typeMustBeCompatibletoBasetype() {
- assertTrue(type.compatibleTo(baseType));
- }
-
- @Test
- public void baseTypeMustNotBeCompatibleToType() {
- assertFalse(baseType.compatibleTo(type));
- }
-
- @Test(expected = EdmException.class)
- public void nullForCompatibleTypeMustResultInEdmException() {
- assertFalse(type.compatibleTo(null));
- }
-
- @Test
- public void getBaseType() {
- assertNull(baseType.getBaseType());
- assertNotNull(type.getBaseType());
- }
-
- @Test
- public void propertiesBehaviour() {
- List<String> propertyNames = baseType.getPropertyNames();
- assertEquals(1, propertyNames.size());
- assertEquals("prop1", baseType.getProperty("prop1").getName());
- }
-
- @Test
- public void propertiesBehaviourWithBaseType() {
- List<String> propertyNames = type.getPropertyNames();
- assertEquals(2, propertyNames.size());
- assertEquals("prop1", type.getProperty("prop1").getName());
- assertEquals("prop2", type.getProperty("prop2").getName());
- }
-
- @Test
- public void navigationPropertiesBehaviour() {
- List<String> navigationPropertyNames = baseType.getNavigationPropertyNames();
- assertEquals(1, navigationPropertyNames.size());
- assertEquals("nav1", baseType.getProperty("nav1").getName());
- }
-
- @Test
- public void navigationPropertiesBehaviourWithBaseType() {
- List<String> navigationPropertyNames = type.getNavigationPropertyNames();
- assertEquals(2, navigationPropertyNames.size());
- assertEquals("nav1", type.getProperty("nav1").getName());
- assertEquals("nav2", type.getProperty("nav2").getName());
- }
-
- @Test
- public void propertyCaching() {
- EdmElement property = type.getProperty("prop1");
- assertTrue(property == type.getProperty("prop1"));
-
- property = type.getProperty("prop2");
- assertTrue(property == type.getProperty("prop2"));
-
- property = type.getProperty("nav1");
- assertTrue(property == type.getProperty("nav1"));
-
- property = type.getProperty("nav2");
- assertTrue(property == type.getProperty("nav2"));
- }
-
- @Test(expected = EdmException.class)
- public void nonExistingBaseType() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- FullQualifiedName typeWithNonexistingBaseTypeName = new FullQualifiedName("namespace", "typeName");
- ComplexType complexTypeForNonexistingBaseType =
- new ComplexType().setBaseType(new FullQualifiedName("wrong", "wrong"));
- complexTypeForNonexistingBaseType.setName("typeName");
- when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType);
- EdmComplexTypeImpl instance =
- EdmComplexTypeImpl.getInstance(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
- instance.getBaseType();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
deleted file mode 100644
index 0889106..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
+++ /dev/null
@@ -1,339 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.ODataException;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmFunctionImport;
-import org.apache.olingo.commons.api.edm.EdmSingleton;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.server.api.edm.provider.ActionImport;
-import org.apache.olingo.server.api.edm.provider.EdmProvider;
-import org.apache.olingo.server.api.edm.provider.EntityContainer;
-import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.server.api.edm.provider.EntitySet;
-import org.apache.olingo.server.api.edm.provider.FunctionImport;
-import org.apache.olingo.server.api.edm.provider.Singleton;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmEntityContainerImplTest {
-
- EdmEntityContainer container;
-
- @Before
- public void setup() {
- EdmProvider provider = new CustomProvider();
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- EntityContainerInfo entityContainerInfo =
- new EntityContainerInfo().setContainerName(new FullQualifiedName("space", "name"));
- container = new EdmEntityContainerImpl(edm, provider, entityContainerInfo);
- }
-
- @Test
- public void getAllEntitySetInitial() {
- List<EdmEntitySet> entitySets = container.getEntitySets();
- assertNotNull(entitySets);
- assertEquals(2, entitySets.size());
- }
-
- @Test
- public void getAllEntitySetsAfterOneWasAlreadyLoaded() {
- EdmEntitySet entitySet = container.getEntitySet("entitySetName");
- List<EdmEntitySet> entitySets = container.getEntitySets();
- assertNotNull(entitySets);
- assertEquals(2, entitySets.size());
- boolean contained = false;
- for (EdmEntitySet es : entitySets) {
- // Already loaded entity set must be the same
- if (es.getName().equals("entitySetName")) {
- assertTrue(entitySet == es);
- contained = true;
- }
- }
- if (!contained) {
- fail("Should have found entity set in this list.");
- }
- }
-
- @Test
- public void getAllSingletonsInitial() {
- List<EdmSingleton> singletons = container.getSingletons();
- assertNotNull(singletons);
- assertEquals(2, singletons.size());
- }
-
- @Test
- public void getAllSingletonsAfterOneWasAlreadyLoaded() {
- EdmSingleton singleton = container.getSingleton("singletonName");
- List<EdmSingleton> singletons = container.getSingletons();
- assertNotNull(singletons);
- assertEquals(2, singletons.size());
- boolean contained = false;
- for (EdmSingleton s : singletons) {
- // Already loaded singleton must be the same
- if (s.getName().equals("singletonName")) {
- assertTrue(singleton == s);
- contained = true;
- }
- }
- if (!contained) {
- fail("Should have found singleton in this list.");
- }
- }
-
- @Test
- public void getAllActionImportsInitial() {
- List<EdmActionImport> actionImports = container.getActionImports();
- assertNotNull(actionImports);
- assertEquals(2, actionImports.size());
- }
-
- @Test
- public void getAllActionImportsAfterOneWasAlreadyLoaded() {
- EdmActionImport actionImport = container.getActionImport("actionImportName");
- List<EdmActionImport> actionImports = container.getActionImports();
- assertNotNull(actionImports);
- assertEquals(2, actionImports.size());
- boolean contained = false;
- for (EdmActionImport ai : actionImports) {
- // Already loaded action import must be the same
- if (ai.getName().equals("actionImportName")) {
- assertTrue(actionImport == ai);
- contained = true;
- }
- }
- if (!contained) {
- fail("Should have found action import in this list.");
- }
- }
-
- @Test
- public void getAllFunctionImportsInitial() {
- List<EdmFunctionImport> functionImports = container.getFunctionImports();
- assertNotNull(functionImports);
- assertEquals(2, functionImports.size());
- }
-
- @Test
- public void getAllFunctionImportsAfterOneWasAlreadyLoaded() {
- EdmFunctionImport functionImport = container.getFunctionImport("functionImportName");
- List<EdmFunctionImport> functionImports = container.getFunctionImports();
- assertNotNull(functionImports);
- assertEquals(2, functionImports.size());
- boolean contained = false;
- for (EdmFunctionImport fi : functionImports) {
- // Already loaded function import must be the same
- if (fi.getName().equals("functionImportName")) {
- assertTrue(functionImport == fi);
- contained = true;
- }
- }
- if (!contained) {
- fail("Should have found function import in this list.");
- }
- }
-
- @Test
- public void checkEdmExceptionConversion() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- FullQualifiedName containerName = new FullQualifiedName("space", "name");
- when(provider.getEntitySet(containerName, null)).thenThrow(new ODataException("msg"));
- when(provider.getSingleton(containerName, null)).thenThrow(new ODataException("msg"));
- when(provider.getFunctionImport(containerName, null)).thenThrow(new ODataException("msg"));
- when(provider.getActionImport(containerName, null)).thenThrow(new ODataException("msg"));
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- EntityContainerInfo entityContainerInfo =
- new EntityContainerInfo().setContainerName(containerName);
- EdmEntityContainer container = new EdmEntityContainerImpl(edm, provider, entityContainerInfo);
- boolean thrown = false;
- try {
- container.getEntitySet(null);
- } catch (EdmException e) {
- thrown = true;
- }
- if (!thrown) {
- fail("Expected EdmException not thrown");
- }
- try {
- container.getSingleton(null);
- } catch (EdmException e) {
- thrown = true;
- }
- if (!thrown) {
- fail("Expected EdmException not thrown");
- }
- try {
- container.getActionImport(null);
- } catch (EdmException e) {
- thrown = true;
- }
- if (!thrown) {
- fail("Expected EdmException not thrown");
- }
- try {
- container.getFunctionImport(null);
- } catch (EdmException e) {
- thrown = true;
- }
- if (!thrown) {
- fail("Expected EdmException not thrown");
- }
- }
-
- @Test
- public void simpleContainerGetter() {
- assertEquals("name", container.getName());
- assertEquals("space", container.getNamespace());
- }
-
- @Test
- public void getExistingFunctionImport() {
- EdmFunctionImport functionImport = container.getFunctionImport("functionImportName");
- assertNotNull(functionImport);
- assertEquals("functionImportName", functionImport.getName());
- // Caching
- assertTrue(functionImport == container.getFunctionImport("functionImportName"));
- }
-
- @Test
- public void getNonExistingFunctionImport() {
- assertNull(container.getFunctionImport(null));
- }
-
- @Test
- public void getExistingActionImport() {
- EdmActionImport actionImport = container.getActionImport("actionImportName");
- assertNotNull(actionImport);
- assertEquals("actionImportName", actionImport.getName());
- // Caching
- assertTrue(actionImport == container.getActionImport("actionImportName"));
- }
-
- @Test
- public void getNonExistingActionImport() {
- assertNull(container.getActionImport(null));
- }
-
- @Test
- public void getExistingSingleton() {
- EdmSingleton singleton = container.getSingleton("singletonName");
- assertNotNull(singleton);
- assertEquals("singletonName", singleton.getName());
- // Caching
- assertTrue(singleton == container.getSingleton("singletonName"));
- }
-
- @Test
- public void getNonExistingSingleton() {
- assertNull(container.getSingleton(null));
- }
-
- @Test
- public void getExistingEntitySet() {
- EdmEntitySet entitySet = container.getEntitySet("entitySetName");
- assertNotNull(entitySet);
- assertEquals("entitySetName", entitySet.getName());
- // Caching
- assertTrue(entitySet == container.getEntitySet("entitySetName"));
- }
-
- @Test
- public void getNonExistingEntitySet() {
- assertNull(container.getEntitySet(null));
- }
-
- private class CustomProvider extends EdmProvider {
- @Override
- public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
- throws ODataException {
- if (entitySetName != null) {
- return new EntitySet().setName("entitySetName");
- }
- return null;
- }
-
- @Override
- public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
- throws ODataException {
- if (singletonName != null) {
- return new Singleton().setName("singletonName");
- }
- return null;
- }
-
- @Override
- public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
- throws ODataException {
- if (actionImportName != null) {
- return new ActionImport().setName("actionImportName");
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
- throws ODataException {
- if (functionImportName != null) {
- return new FunctionImport().setName("functionImportName");
- }
- return null;
- }
-
- @Override
- public EntityContainer getEntityContainer() throws ODataException {
- EntityContainer container = new EntityContainer();
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(new EntitySet().setName("entitySetName"));
- entitySets.add(new EntitySet().setName("entitySetName2"));
- container.setEntitySets(entitySets);
-
- List<Singleton> singletons = new ArrayList<Singleton>();
- singletons.add(new Singleton().setName("singletonName"));
- singletons.add(new Singleton().setName("singletonName2"));
- container.setSingletons(singletons);
-
- List<ActionImport> actionImports = new ArrayList<ActionImport>();
- actionImports.add(new ActionImport().setName("actionImportName"));
- actionImports.add(new ActionImport().setName("actionImportName2"));
- container.setActionImports(actionImports);
-
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(new FunctionImport().setName("functionImportName"));
- functionImports.add(new FunctionImport().setName("functionImportName2"));
- container.setFunctionImports(functionImports);
-
- return container;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
deleted file mode 100644
index 539e486..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
+++ /dev/null
@@ -1,81 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-import org.apache.olingo.server.api.edm.provider.EdmProvider;
-import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.server.api.edm.provider.EntitySet;
-import org.apache.olingo.server.api.edm.provider.EntityType;
-import org.apache.olingo.server.api.edm.provider.NavigationPropertyBinding;
-import org.apache.olingo.server.api.edm.provider.PropertyRef;
-import org.junit.Test;
-
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmEntitySetImplTest {
-
- @Test
- public void entitySet() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- final FullQualifiedName typeName = new FullQualifiedName("ns", "entityType");
- final EntityType entityTypeProvider = new EntityType()
- .setName(typeName.getName())
- .setKey(Arrays.asList(new PropertyRef().setPropertyName("Id")));
- when(provider.getEntityType(typeName)).thenReturn(entityTypeProvider);
-
- final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
- final EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(containerName);
- when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
- final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo);
-
- final String entitySetName = "entitySet";
- final EntitySet entitySetProvider = new EntitySet()
- .setName(entitySetName)
- .setType(typeName)
- .setIncludeInServiceDocument(true)
- .setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName(entitySetName))));
- when(provider.getEntitySet(containerName, entitySetName)).thenReturn(entitySetProvider);
-
- final EdmEntitySet entitySet = new EdmEntitySetImpl(edm, entityContainer, entitySetProvider);
- assertEquals(entitySetName, entityContainer.getEntitySet(entitySetName).getName());
- assertEquals(entitySetName, entitySet.getName());
- final EdmEntityType entityType = entitySet.getEntityType();
- assertEquals(typeName.getNamespace(), entityType.getNamespace());
- assertEquals(typeName.getName(), entityType.getName());
- assertEquals(entityContainer, entitySet.getEntityContainer());
- assertNull(entitySet.getRelatedBindingTarget(null));
- final EdmBindingTarget target = entitySet.getRelatedBindingTarget("path");
- assertEquals(entitySetName, target.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
deleted file mode 100644
index 42af891..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
+++ /dev/null
@@ -1,383 +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.server.core.edm.provider;
-
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmElement;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.server.api.edm.provider.ComplexType;
-import org.apache.olingo.server.api.edm.provider.EdmProvider;
-import org.apache.olingo.server.api.edm.provider.EntityType;
-import org.apache.olingo.server.api.edm.provider.NavigationProperty;
-import org.apache.olingo.server.api.edm.provider.Property;
-import org.apache.olingo.server.api.edm.provider.PropertyRef;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EdmEntityTypeImplTest {
-
- private EdmEntityType baseType;
-
- private EdmEntityType typeWithBaseType;
-
- private EdmEntityType typeWithComplexKey;
-
- @Before
- public void setupTypes() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
- EntityType baseType = new EntityType();
- baseType.setName(baseName.getName());
- List<Property> properties = new ArrayList<Property>();
- properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- baseType.setProperties(properties);
- List<PropertyRef> key = new ArrayList<PropertyRef>();
- key.add(new PropertyRef().setPropertyName("Id"));
- baseType.setKey(key);
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("nav1"));
- baseType.setNavigationProperties(navigationProperties);
- when(provider.getEntityType(baseName)).thenReturn(baseType);
-
- this.baseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
-
- FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
- EntityType type = new EntityType();
- type.setName(typeName.getName());
- type.setBaseType(baseName);
- List<Property> typeProperties = new ArrayList<Property>();
- typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- type.setProperties(typeProperties);
- List<NavigationProperty> typeNavigationProperties = new ArrayList<NavigationProperty>();
- typeNavigationProperties.add(new NavigationProperty().setName("nav2"));
- type.setNavigationProperties(typeNavigationProperties);
- when(provider.getEntityType(typeName)).thenReturn(type);
-
- typeWithBaseType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
-
- FullQualifiedName typeWithComplexKeyName = new FullQualifiedName("namespace", "typeName");
- EntityType typeWithComplexKeyProvider = new EntityType();
- typeWithComplexKeyProvider.setName(typeWithComplexKeyName.getName());
- List<Property> typeWithComplexKeyProperties = new ArrayList<Property>();
- typeWithComplexKeyProperties.add(new Property().setName("Id").setType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
-
- List<Property> complexTypeProperties = new ArrayList<Property>();
- complexTypeProperties.add(new Property().setName("ComplexPropName").setType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- FullQualifiedName complexTypeName = new FullQualifiedName("namespace", "complexTypeName");
- when(provider.getComplexType(complexTypeName)).thenReturn(
- new ComplexType().setName("complexTypeName").setProperties(complexTypeProperties));
-
- typeWithComplexKeyProperties.add(new Property().setName("Comp").setType(complexTypeName));
- typeWithComplexKeyProvider.setProperties(typeWithComplexKeyProperties);
- List<PropertyRef> keyForTypeWithComplexKey = new ArrayList<PropertyRef>();
- keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("Id"));
- keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("ComplexPropName").setAlias("alias").setPath(
- "Comp/ComplexPropName"));
- typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey);
- when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider);
-
- typeWithComplexKey = EdmEntityTypeImpl.getInstance(edm, typeWithComplexKeyName, typeWithComplexKeyProvider);
- }
-
- @Test
- public void testAbstractBaseTypeWithoutKey() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
- EntityType baseType = new EntityType();
- baseType.setName(baseName.getName());
- List<Property> properties = new ArrayList<Property>();
- properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- baseType.setProperties(properties);
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("nav1"));
- baseType.setNavigationProperties(navigationProperties);
- when(provider.getEntityType(baseName)).thenReturn(baseType);
- baseType.setAbstract(true);
- EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
-
- assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
- assertEquals("Id", edmAbstarctBaseType.getPropertyNames().get(0));
- assertEquals("Name", edmAbstarctBaseType.getPropertyNames().get(1));
-
- FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
- EntityType type = new EntityType();
- type.setName(typeName.getName());
- type.setBaseType(baseName);
- List<Property> typeProperties = new ArrayList<Property>();
- typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- type.setProperties(typeProperties);
- List<PropertyRef> key = new ArrayList<PropertyRef>();
- key.add(new PropertyRef().setPropertyName("email"));
- type.setKey(key);
- List<NavigationProperty> typeNavigationProperties = new ArrayList<NavigationProperty>();
- typeNavigationProperties.add(new NavigationProperty().setName("nav2"));
- type.setNavigationProperties(typeNavigationProperties);
- when(provider.getEntityType(typeName)).thenReturn(type);
-
- EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
-
- assertNotNull(edmType.getBaseType());
- assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
-
- assertEquals(1, edmType.getKeyPropertyRefs().size());
- assertEquals("email", edmType.getKeyPredicateNames().get(0));
-
- assertEquals(4, edmType.getPropertyNames().size());
- assertEquals("Id", edmType.getPropertyNames().get(0));
- assertEquals("Name", edmType.getPropertyNames().get(1));
- assertEquals("address", edmType.getPropertyNames().get(2));
- assertEquals("email", edmType.getPropertyNames().get(3));
-
- assertEquals(2, edmType.getNavigationPropertyNames().size());
- assertEquals("nav1", edmType.getNavigationPropertyNames().get(0));
- assertEquals("nav2", edmType.getNavigationPropertyNames().get(1));
- }
-
- @Test
- public void testAbstractBaseTypeWithtKey() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
- EntityType baseType = new EntityType();
- baseType.setName(baseName.getName());
- List<Property> properties = new ArrayList<Property>();
- properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- baseType.setProperties(properties);
- List<PropertyRef> key = new ArrayList<PropertyRef>();
- key.add(new PropertyRef().setPropertyName("Id"));
- baseType.setKey(key);
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("nav1"));
- baseType.setNavigationProperties(navigationProperties);
- when(provider.getEntityType(baseName)).thenReturn(baseType);
- baseType.setAbstract(true);
- EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
-
- FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
- EntityType type = new EntityType();
- type.setName(typeName.getName());
- type.setBaseType(baseName);
- List<Property> typeProperties = new ArrayList<Property>();
- typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- type.setProperties(typeProperties);
- List<NavigationProperty> typeNavigationProperties = new ArrayList<NavigationProperty>();
- typeNavigationProperties.add(new NavigationProperty().setName("nav2"));
- type.setNavigationProperties(typeNavigationProperties);
- when(provider.getEntityType(typeName)).thenReturn(type);
- EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
-
- assertNotNull(edmType.getBaseType());
- assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
-
- assertEquals(1, edmType.getKeyPropertyRefs().size());
- assertEquals("Id", edmType.getKeyPredicateNames().get(0));
-
- assertEquals(4, edmType.getPropertyNames().size());
- assertEquals("Id", edmType.getPropertyNames().get(0));
- assertEquals("Name", edmType.getPropertyNames().get(1));
- assertEquals("address", edmType.getPropertyNames().get(2));
- assertEquals("email", edmType.getPropertyNames().get(3));
-
- assertEquals(2, edmType.getNavigationPropertyNames().size());
- assertEquals("nav1", edmType.getNavigationPropertyNames().get(0));
- assertEquals("nav2", edmType.getNavigationPropertyNames().get(1));
- }
-
- @Test
- public void hasStream() {
- assertFalse(typeWithBaseType.hasStream());
- }
-
- @Test
- public void complexKeyWithAlias() {
- List<String> keyPredicateNames = typeWithComplexKey.getKeyPredicateNames();
- assertEquals(2, keyPredicateNames.size());
- assertEquals("Id", keyPredicateNames.get(0));
- assertEquals("alias", keyPredicateNames.get(1));
-
- EdmKeyPropertyRef keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("Id");
- assertNotNull(keyPropertyRef);
- assertEquals("Id", keyPropertyRef.getKeyPropertyName());
- assertNull(keyPropertyRef.getAlias());
- EdmProperty keyProperty = keyPropertyRef.getProperty();
- assertNotNull(keyProperty);
- assertEquals(typeWithComplexKey.getProperty("Id"), keyProperty);
-
- keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("alias");
- assertNotNull(keyPropertyRef);
- assertEquals("ComplexPropName", keyPropertyRef.getKeyPropertyName());
- assertEquals("alias", keyPropertyRef.getAlias());
- assertEquals("Comp/ComplexPropName", keyPropertyRef.getPath());
-
- keyProperty = keyPropertyRef.getProperty();
- assertNotNull(keyProperty);
- EdmElement complexProperty = typeWithComplexKey.getProperty("Comp");
- EdmComplexType complexType = (EdmComplexType) complexProperty.getType();
- assertNotNull(complexType);
- assertEquals(complexType.getProperty("ComplexPropName"), keyProperty);
- }
-
- @Test
- public void keyBehaviour() {
- List<String> keyPredicateNames = baseType.getKeyPredicateNames();
- assertEquals(1, keyPredicateNames.size());
- assertEquals("Id", keyPredicateNames.get(0));
-
- EdmKeyPropertyRef keyPropertyRef = baseType.getKeyPropertyRef("Id");
- assertNotNull(keyPropertyRef);
- assertEquals("Id", keyPropertyRef.getKeyPropertyName());
- assertNull(keyPropertyRef.getAlias());
-
- EdmProperty keyProperty = keyPropertyRef.getProperty();
- assertNotNull(keyProperty);
- assertEquals(baseType.getProperty("Id"), keyProperty);
-
- List<EdmKeyPropertyRef> keyPropertyRefs = baseType.getKeyPropertyRefs();
- assertNotNull(keyPropertyRefs);
- assertEquals(1, keyPropertyRefs.size());
- assertEquals("Id", keyPropertyRefs.get(0).getKeyPropertyName());
- }
-
- @Test
- public void keyBehaviourWithBasetype() {
- List<String> keyPredicateNames = typeWithBaseType.getKeyPredicateNames();
- assertEquals(1, keyPredicateNames.size());
- assertEquals("Id", keyPredicateNames.get(0));
-
- EdmKeyPropertyRef keyPropertyRef = typeWithBaseType.getKeyPropertyRef("Id");
- assertNotNull(keyPropertyRef);
- assertEquals("Id", keyPropertyRef.getKeyPropertyName());
- assertNull(keyPropertyRef.getAlias());
-
- List<EdmKeyPropertyRef> keyPropertyRefs = typeWithBaseType.getKeyPropertyRefs();
- assertNotNull(keyPropertyRefs);
- assertEquals(1, keyPropertyRefs.size());
- assertEquals("Id", keyPropertyRefs.get(0).getKeyPropertyName());
- assertTrue(keyPropertyRefs == typeWithBaseType.getKeyPropertyRefs());
- }
-
- @Test
- public void getBaseType() {
- assertNull(baseType.getBaseType());
- assertNotNull(typeWithBaseType.getBaseType());
- }
-
- @Test
- public void propertiesBehaviour() {
- List<String> propertyNames = baseType.getPropertyNames();
- assertEquals(2, propertyNames.size());
- assertEquals("Id", baseType.getProperty("Id").getName());
- assertEquals("Name", baseType.getProperty("Name").getName());
- }
-
- @Test
- public void propertiesBehaviourWithBaseType() {
- List<String> propertyNames = typeWithBaseType.getPropertyNames();
- assertEquals(4, propertyNames.size());
- assertEquals("Id", typeWithBaseType.getProperty("Id").getName());
- assertEquals("Name", typeWithBaseType.getProperty("Name").getName());
- assertEquals("address", typeWithBaseType.getProperty("address").getName());
- assertEquals("email", typeWithBaseType.getProperty("email").getName());
- }
-
- @Test
- public void navigationPropertiesBehaviour() {
- List<String> navigationPropertyNames = baseType.getNavigationPropertyNames();
- assertEquals(1, navigationPropertyNames.size());
- assertEquals("nav1", baseType.getProperty("nav1").getName());
- }
-
- @Test
- public void navigationPropertiesBehaviourWithBaseType() {
- List<String> navigationPropertyNames = typeWithBaseType.getNavigationPropertyNames();
- assertEquals(2, navigationPropertyNames.size());
- assertEquals("nav1", typeWithBaseType.getProperty("nav1").getName());
- assertEquals("nav2", typeWithBaseType.getProperty("nav2").getName());
- }
-
- @Test
- public void propertyCaching() {
- EdmElement property = typeWithBaseType.getProperty("Id");
- assertTrue(property == typeWithBaseType.getProperty("Id"));
-
- property = typeWithBaseType.getProperty("address");
- assertTrue(property == typeWithBaseType.getProperty("address"));
-
- property = typeWithBaseType.getProperty("nav1");
- assertTrue(property == typeWithBaseType.getProperty("nav1"));
-
- property = typeWithBaseType.getProperty("nav2");
- assertTrue(property == typeWithBaseType.getProperty("nav2"));
- }
-
- @Test
- public void abstractTypeDoesNotNeedKey() {
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- EntityType entityType = new EntityType().setName("n").setAbstract(true);
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
- }
-
- @Test(expected = EdmException.class)
- public void invalidBaseType() {
- EdmProviderImpl edm = mock(EdmProviderImpl.class);
- EntityType entityType = new EntityType().setName("n").setBaseType(new FullQualifiedName("wrong", "wrong"));
- EdmEntityTypeImpl instance = EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
- instance.getBaseType();
- }
-
- @Test
- public void abstractTypeWithAbstractBaseTypeDoesNotNeedKey() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- FullQualifiedName baseName = new FullQualifiedName("n", "base");
- when(provider.getEntityType(baseName)).thenReturn(new EntityType().setName("base").setAbstract(true));
- EntityType entityType = new EntityType().setName("n").setAbstract(true).setBaseType(baseName);
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
- }
-
-}