[OLINGO-62] Even more edm tests
This commit is contained in:
parent
ab6dff2926
commit
757eb54c08
|
@ -36,7 +36,6 @@ import org.apache.olingo.odata4.commons.api.edm.provider.FunctionImport;
|
|||
import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
|
||||
import org.apache.olingo.odata4.commons.api.exception.ODataException;
|
||||
|
||||
|
||||
public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer {
|
||||
|
||||
private final FullQualifiedName entityContainerName;
|
||||
|
@ -66,7 +65,9 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
|
|||
Singleton providerSingleton = provider.getSingleton(entityContainerName, singletonName);
|
||||
if (providerSingleton != null) {
|
||||
singleton = new EdmSingletonImpl(edm, this, providerSingleton);
|
||||
singletons.put(singletonName, singleton);
|
||||
if (singleton != null) {
|
||||
singletons.put(singletonName, singleton);
|
||||
}
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
@ -83,7 +84,9 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
|
|||
EntitySet providerEntitySet = provider.getEntitySet(entityContainerName, entitySetName);
|
||||
if (providerEntitySet != null) {
|
||||
entitySet = new EdmEntitySetImpl(edm, this, providerEntitySet);
|
||||
entitySets.put(entitySetName, entitySet);
|
||||
if (entitySet != null) {
|
||||
entitySets.put(entitySetName, entitySet);
|
||||
}
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
@ -100,7 +103,9 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
|
|||
ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName);
|
||||
if (providerImport != null) {
|
||||
actionImport = new EdmActionImportImpl(edm, actionImportName, this, providerImport);
|
||||
actionImports.put(actionImportName, actionImport);
|
||||
if (actionImport != null) {
|
||||
actionImports.put(actionImportName, actionImport);
|
||||
}
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
@ -117,7 +122,9 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
|
|||
FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName);
|
||||
if (providerImport != null) {
|
||||
functionImport = new EdmFunctionImportImpl(edm, functionImportName, this, providerImport);
|
||||
functionImports.put(functionImportName, functionImport);
|
||||
if (functionImport != null) {
|
||||
functionImports.put(functionImportName, functionImport);
|
||||
}
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
* 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.odata4.commons.core.edm.provider;
|
||||
|
||||
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;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.ActionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.Target;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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.getAction(actionFqn, null, null)).thenReturn(action);
|
||||
|
||||
entitySet = mock(EdmEntitySet.class);
|
||||
when(container.getEntitySet("entitySetName")).thenReturn(entitySet);
|
||||
actionImport = new EdmActionImportImpl(edm, "actionImportName", container, providerActionImport);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleActionTest() {
|
||||
assertEquals("actionImportName", actionImport.getName());
|
||||
assertTrue(container == actionImport.getEntityContainer());
|
||||
assertTrue(action == actionImport.getAction());
|
||||
}
|
||||
|
||||
@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), "actionImportName", 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, "actionImportName", container, providerActionImport);
|
||||
actionImport.getReturnedEntitySet();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
/*******************************************************************************
|
||||
* 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.odata4.commons.core.edm.provider;
|
||||
|
||||
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;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.ActionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.EntityContainerInfo;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.EntitySet;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.FunctionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
|
||||
import org.apache.olingo.odata4.commons.api.exception.ODataException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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 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(FullQualifiedName entityContainer, String entitySetName) throws ODataException {
|
||||
if (entitySetName != null) {
|
||||
return new EntitySet().setName("entitySetName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Singleton getSingleton(FullQualifiedName entityContainer, String singletonName) throws ODataException {
|
||||
if (singletonName != null) {
|
||||
return new Singleton().setName("singletonName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionImport getActionImport(FullQualifiedName entityContainer, String actionImportName)
|
||||
throws ODataException {
|
||||
if (actionImportName != null) {
|
||||
return new ActionImport().setName("singletonName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionImport getFunctionImport(FullQualifiedName entityContainer, String functionImportName)
|
||||
throws ODataException {
|
||||
if (functionImportName != null) {
|
||||
return new FunctionImport().setName("singletonName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue