Commit 87619f4c authored by Rodrigo Carneiro Henrique's avatar Rodrigo Carneiro Henrique
Browse files

[SCS-230]: Refactoring da API, demos e testes Java


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/scs/core/java/trunk@119573 ae0415b3-e90b-0410-900d-d0be9363c56b
parent c57dc117
package scs.core;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import junit.framework.Assert;
......@@ -115,48 +118,154 @@ public final class ComponentContextTest {
public void getFacetByName() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.getFacetByName(null);
}
@Test
public void getFacetByName2() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
Assert.assertNull(component.getFacetByName(""));
}
@Test(expected = IllegalArgumentException.class)
public void getReceptacleByName() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.getReceptacleByName(null);
}
@Test
public void getReceptacleByName2() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
Assert.assertNull(component.getReceptacleByName(""));
}
@Test
public void getIComponent() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
IComponent iComponent = component.getIComponent();
Assert.assertNotNull(iComponent);
String iComponentFacetName = "IComponent";
Facet facet = component.getFacetByName(iComponentFacetName);
Facet facet =
component.getFacetByName(ComponentContext.ICOMPONENT_FACET_NAME);
Assert.assertNotNull(facet);
FacetDescription description = facet.getDescription();
Assert.assertEquals(iComponent, description.facet_ref);
Assert.assertEquals(IComponentHelper.id(), facet.getInterfaceName());
Assert.assertEquals(IComponentHelper.id(), description.interface_name);
Assert.assertEquals(iComponentFacetName, facet.getName());
Assert.assertEquals(iComponentFacetName, description.name);
Assert
.assertEquals(ComponentContext.ICOMPONENT_FACET_NAME, facet.getName());
Assert.assertEquals(ComponentContext.ICOMPONENT_FACET_NAME,
description.name);
}
@Test
public void getIComponent2() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
IComponent iComponent = component.getIComponent();
component.removeFacet(ComponentContext.ICOMPONENT_FACET_NAME);
iComponent = component.getIComponent();
Assert.assertNull(iComponent);
}
@Test
public void getIReceptacles() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
String iReceptaclesFacetName = "IReceptacles";
Facet facet = component.getFacetByName(iReceptaclesFacetName);
Facet facet =
component.getFacetByName(ComponentContext.IRECEPTACLES_FACET_NAME);
Assert.assertNotNull(facet);
FacetDescription description = facet.getDescription();
Assert.assertEquals(IReceptaclesHelper.id(), facet.getInterfaceName());
Assert.assertEquals(IReceptaclesHelper.id(), description.interface_name);
Assert.assertEquals(iReceptaclesFacetName, facet.getName());
Assert.assertEquals(iReceptaclesFacetName, description.name);
Assert.assertEquals(ComponentContext.IRECEPTACLES_FACET_NAME, facet
.getName());
Assert.assertEquals(ComponentContext.IRECEPTACLES_FACET_NAME,
description.name);
}
@Test
public void getIMetaInterface() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
String iMetaInterfaceFacetName = "IMetaInterface";
Facet facet = component.getFacetByName(iMetaInterfaceFacetName);
Facet facet =
component.getFacetByName(ComponentContext.IMETAINTERFACE_FACET_NAME);
Assert.assertNotNull(facet);
FacetDescription description = facet.getDescription();
Assert.assertEquals(IMetaInterfaceHelper.id(), facet.getInterfaceName());
Assert.assertEquals(IMetaInterfaceHelper.id(), description.interface_name);
Assert.assertEquals(iMetaInterfaceFacetName, facet.getName());
Assert.assertEquals(iMetaInterfaceFacetName, description.name);
Assert.assertEquals(ComponentContext.IMETAINTERFACE_FACET_NAME, facet
.getName());
Assert.assertEquals(ComponentContext.IMETAINTERFACE_FACET_NAME,
description.name);
}
@Test
public void putFacet() throws SCSException {
String facetName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putFacet(facetName, IComponentHelper.id(), new IComponentServant(
component));
Assert.assertNotNull(component.getFacetByName(facetName));
}
@Test
public void removeFacet() throws SCSException {
String facetName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putFacet(facetName, IComponentHelper.id(), new IComponentServant(
component));
Assert.assertNotNull(component.getFacetByName(facetName));
component.removeFacet(facetName);
Assert.assertNull(component.getFacetByName("nome"));
}
@Test
public void removeFacet2() throws SCSException {
String facetName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.removeFacet(facetName);
}
@Test
public void putReceptacle() throws SCSException {
String receptacleName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putReceptacle(receptacleName, IComponentHelper.id(), false);
Assert.assertNotNull(component.getReceptacleByName(receptacleName));
}
@Test
public void removeReceptacle() throws SCSException {
String receptacleName = "nome";
ComponentContext component = new ComponentContext(orb, poa, componentId);
component.putReceptacle("nome", IComponentHelper.id(), false);
Assert.assertNotNull(component.getReceptacleByName(receptacleName));
component.removeReceptacle(receptacleName);
Assert.assertNull(component.getReceptacleByName(receptacleName));
}
@Test
public void activateComponent() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
Map<String, SCSException> errors = component.activateComponent();
Assert.assertEquals(component.getFacets().size(), errors.size());
}
@Test
public void activateComponent2() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
Collection<Facet> facets = component.getFacets();
Set<String> facetsNames = new HashSet<String>(facets.size());
for (Facet facet : facets) {
facetsNames.add(facet.getName());
}
for (String facetName : facetsNames) {
component.removeFacet(facetName);
}
Map<String, SCSException> errors = component.activateComponent();
Assert.assertEquals(0, errors.size());
}
@Test
public void deactivateComponent() throws SCSException {
ComponentContext component = new ComponentContext(orb, poa, componentId);
Map<String, SCSException> errors = component.deactivateComponent();
Assert.assertEquals(0, errors.size());
}
}
......@@ -14,6 +14,9 @@ import scs.core.exception.SCSException;
public final class IComponentTest {
private static final String COMPONENT_NAME = "componente";
private static final byte COMPONENT_MAJOR_VERSION = 1;
private static final byte COMPONENT_MINOR_VERSION = 0;
private static final byte COMPONENT_PATCH_VERSION = 0;
private static final String COMPONENT_PLATFORM_SPEC = "java";
private static ComponentContext context;
......@@ -26,7 +29,8 @@ public final class IComponentTest {
poa.the_POAManager().activate();
ComponentId componentId =
new ComponentId(COMPONENT_NAME, (byte) 1, (byte) 0, (byte) 0,
new ComponentId(COMPONENT_NAME, COMPONENT_MAJOR_VERSION,
COMPONENT_MINOR_VERSION, COMPONENT_PATCH_VERSION,
COMPONENT_PLATFORM_SPEC);
context = new ComponentContext(orb, poa, componentId);
......@@ -50,6 +54,9 @@ public final class IComponentTest {
IComponent component = IComponentHelper.narrow(facet.getReference());
ComponentId id = component.getComponentId();
Assert.assertEquals(COMPONENT_NAME, id.name);
Assert.assertEquals(COMPONENT_MAJOR_VERSION, id.major_version);
Assert.assertEquals(COMPONENT_MINOR_VERSION, id.minor_version);
Assert.assertEquals(COMPONENT_PATCH_VERSION, id.patch_version);
Assert.assertEquals(COMPONENT_PLATFORM_SPEC, id.platform_spec);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment