[OLINGO-786] Implement Tests for qualifiermapkey

This commit is contained in:
Christian Amend 2015-10-08 13:43:54 +02:00
parent 3647a63177
commit 546cf34c57
4 changed files with 206 additions and 17 deletions

View File

@ -6,9 +6,9 @@
* 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
@ -18,17 +18,21 @@
*/
package org.apache.olingo.commons.core.edm;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
public class TargetQualifierMapKey {
private final FullQualifiedName targetName;
private final String qualifier;
private final FullQualifiedName targetName;
private final String qualifier;
public TargetQualifierMapKey(FullQualifiedName targetName, String qualifier) {
this.targetName = targetName;
this.qualifier = qualifier;
}
if (targetName == null) {
throw new EdmException("targetName for TargetQualifierMapKey must not be null.");
}
this.targetName = targetName;
this.qualifier = qualifier;
}
@Override
public int hashCode() {
@ -68,5 +72,4 @@ public class TargetQualifierMapKey {
return true;
}
}

View File

@ -6,9 +6,9 @@
* 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
@ -247,6 +247,40 @@ public class EdmImplCachingTest {
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
public void setup() {
edm = new LocalEdm();
@ -417,12 +451,26 @@ public class EdmImplCachingTest {
@Override
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
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;
}
}
}

View File

@ -6,9 +6,9 @@
* 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
@ -149,6 +149,26 @@ public class EdmImplCallCreateTest {
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
public void setup() {
edm = new LocalEdm();
@ -281,12 +301,22 @@ public class EdmImplCallCreateTest {
@Override
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
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;
}
}
}

View File

@ -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);
}
}