[OLINGO-786] Implement Tests for qualifiermapkey
This commit is contained in:
parent
3647a63177
commit
546cf34c57
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -18,17 +18,21 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.commons.core.edm;
|
package org.apache.olingo.commons.core.edm;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
|
||||||
public class TargetQualifierMapKey {
|
public class TargetQualifierMapKey {
|
||||||
|
|
||||||
private final FullQualifiedName targetName;
|
private final FullQualifiedName targetName;
|
||||||
private final String qualifier;
|
private final String qualifier;
|
||||||
|
|
||||||
public TargetQualifierMapKey(FullQualifiedName targetName, String qualifier) {
|
public TargetQualifierMapKey(FullQualifiedName targetName, String qualifier) {
|
||||||
this.targetName = targetName;
|
if (targetName == null) {
|
||||||
this.qualifier = qualifier;
|
throw new EdmException("targetName for TargetQualifierMapKey must not be null.");
|
||||||
}
|
}
|
||||||
|
this.targetName = targetName;
|
||||||
|
this.qualifier = qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
@ -68,5 +72,4 @@ public class TargetQualifierMapKey {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -247,6 +247,40 @@ public class EdmImplCachingTest {
|
||||||
assertNotSame(function, function2);
|
assertNotSame(function, function2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cacheTerm() {
|
||||||
|
EdmTerm term1 = edm.getTerm(NAME1);
|
||||||
|
assertNotNull(term1);
|
||||||
|
|
||||||
|
EdmTerm cachedTerm = edm.getTerm(NAME1);
|
||||||
|
assertNotNull(cachedTerm);
|
||||||
|
|
||||||
|
assertEquals(term1, cachedTerm);
|
||||||
|
assertTrue(term1 == cachedTerm);
|
||||||
|
|
||||||
|
EdmTerm term2 = edm.getTerm(NAME2);
|
||||||
|
assertNotNull(term2);
|
||||||
|
|
||||||
|
assertNotSame(term1, term2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cacheAnnotationsGroup() {
|
||||||
|
EdmAnnotations annotationGroup1 = edm.getAnnotationGroup(NAME1, null);
|
||||||
|
assertNotNull(annotationGroup1);
|
||||||
|
|
||||||
|
EdmAnnotations cachedAnnotationGroup = edm.getAnnotationGroup(NAME1, null);
|
||||||
|
assertNotNull(cachedAnnotationGroup);
|
||||||
|
|
||||||
|
assertEquals(annotationGroup1, cachedAnnotationGroup);
|
||||||
|
assertTrue(annotationGroup1 == cachedAnnotationGroup);
|
||||||
|
|
||||||
|
EdmAnnotations annotationGroup2 = edm.getAnnotationGroup(NAME1, "");
|
||||||
|
assertNotNull(annotationGroup2);
|
||||||
|
|
||||||
|
assertNotSame(annotationGroup1, annotationGroup2);
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
edm = new LocalEdm();
|
edm = new LocalEdm();
|
||||||
|
@ -417,12 +451,26 @@ public class EdmImplCachingTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EdmTerm createTerm(final FullQualifiedName termName) {
|
protected EdmTerm createTerm(final FullQualifiedName termName) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
if(NAME1.equals(termName) || NAME2.equals(termName)){
|
||||||
|
EdmTerm term = mock(EdmTerm.class);
|
||||||
|
when(term.getFullQualifiedName()).thenReturn(termName);
|
||||||
|
return term;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName target, String qualifier) {
|
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName target, String qualifier) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
if(NAME1.equals(target) && qualifier == null){
|
||||||
|
EdmAnnotations annotationGroup = mock(EdmAnnotations.class);
|
||||||
|
when(annotationGroup.getQualifier()).thenReturn(null);
|
||||||
|
return annotationGroup;
|
||||||
|
}else if(NAME1.equals(target) && "".equals(qualifier)){
|
||||||
|
EdmAnnotations annotationGroup = mock(EdmAnnotations.class);
|
||||||
|
when(annotationGroup.getQualifier()).thenReturn("");
|
||||||
|
return annotationGroup;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@ -149,6 +149,26 @@ public class EdmImplCallCreateTest {
|
||||||
assertNull(edm.getUnboundFunction(WRONG_FQN, null));
|
assertNull(edm.getUnboundFunction(WRONG_FQN, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void callCreateTerm() {
|
||||||
|
EdmTerm term = edm.getTerm(FQN);
|
||||||
|
assertNotNull(term);
|
||||||
|
|
||||||
|
assertEquals(FQN, term.getFullQualifiedName());
|
||||||
|
|
||||||
|
assertNull(edm.getTerm(WRONG_FQN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void callCreateAnnotationGroup() {
|
||||||
|
EdmAnnotations annotationGroup = edm.getAnnotationGroup(FQN, null);
|
||||||
|
assertNotNull(annotationGroup);
|
||||||
|
|
||||||
|
assertEquals(null, annotationGroup.getQualifier());
|
||||||
|
|
||||||
|
assertNull(edm.getAnnotationGroup(WRONG_FQN, null));
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
edm = new LocalEdm();
|
edm = new LocalEdm();
|
||||||
|
@ -281,12 +301,22 @@ public class EdmImplCallCreateTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EdmTerm createTerm(final FullQualifiedName termName) {
|
protected EdmTerm createTerm(final FullQualifiedName termName) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
if (FQN.equals(termName)) {
|
||||||
|
EdmTerm term = mock(EdmTerm.class);
|
||||||
|
when(term.getFullQualifiedName()).thenReturn(FQN);
|
||||||
|
return term;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName targetName, String qualifier) {
|
protected EdmAnnotations createAnnotationGroup(final FullQualifiedName targetName, String qualifier) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
if (FQN.equals(targetName) && qualifier == null) {
|
||||||
|
EdmAnnotations annotationGroup = mock(EdmAnnotations.class);
|
||||||
|
when(annotationGroup.getQualifier()).thenReturn(qualifier);
|
||||||
|
return annotationGroup;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* 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.commons.core.edm;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmException;
|
||||||
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TargetQualifierMapKeyTest {
|
||||||
|
|
||||||
|
private static final FullQualifiedName TARGET_NAME_1 = new FullQualifiedName("namespace", "name");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidParametersTest() {
|
||||||
|
createAndCheckForEdmException(null, null);
|
||||||
|
createAndCheckForEdmException(null, "qualifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validParametersTest() {
|
||||||
|
new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEqualsMethod() {
|
||||||
|
TargetQualifierMapKey key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
TargetQualifierMapKey key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), "qualifier");
|
||||||
|
assertEquals(key1, key1);
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), "qualifier");
|
||||||
|
assertEquals(key1, key2);
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
key2 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
assertEquals(key1, key2);
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), null);
|
||||||
|
assertEquals(key1, key2);
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
key2 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
assertNotSame(key1, key2);
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), null);
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "wrong"), null);
|
||||||
|
assertNotSame(key1, key2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHashMethod() {
|
||||||
|
TargetQualifierMapKey key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
TargetQualifierMapKey key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), "qualifier");
|
||||||
|
assertEquals(key1.hashCode(), key1.hashCode());
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), "qualifier");
|
||||||
|
assertEquals(key1.hashCode(), key2.hashCode());
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
key2 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
assertEquals(key1.hashCode(), key2.hashCode());
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), null);
|
||||||
|
assertEquals(key1.hashCode(), key2.hashCode());
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(TARGET_NAME_1, "qualifier");
|
||||||
|
key2 = new TargetQualifierMapKey(TARGET_NAME_1, null);
|
||||||
|
assertNotSame(key1.hashCode(), key2.hashCode());
|
||||||
|
|
||||||
|
key1 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "name"), null);
|
||||||
|
key2 = new TargetQualifierMapKey(new FullQualifiedName("namespace", "wrong"), null);
|
||||||
|
assertNotSame(key1.hashCode(), key2.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndCheckForEdmException(final FullQualifiedName fqn, final String qualifier) {
|
||||||
|
try {
|
||||||
|
new TargetQualifierMapKey(fqn, qualifier);
|
||||||
|
} catch (EdmException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fail("EdmException expected for parameters: " + fqn + " " + qualifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue