From 42163ea874e7ad6ee26c5b4a36a185db85b631fa Mon Sep 17 00:00:00 2001 From: Shamseen Date: Wed, 26 Jul 2017 15:59:55 -0400 Subject: [PATCH] #6 predefining PROPERTY if empty + unit tests --- .../cidarlab/eugene/dom/ComponentType.java | 254 ++--- .../eugene/units/DeclarationsTest.java | 956 +++++++++--------- 2 files changed, 608 insertions(+), 602 deletions(-) diff --git a/src/main/java/org/cidarlab/eugene/dom/ComponentType.java b/src/main/java/org/cidarlab/eugene/dom/ComponentType.java index 4dab949..d9582c4 100644 --- a/src/main/java/org/cidarlab/eugene/dom/ComponentType.java +++ b/src/main/java/org/cidarlab/eugene/dom/ComponentType.java @@ -26,150 +26,160 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - package org.cidarlab.eugene.dom; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.cidarlab.eugene.constants.EugeneConstants; import org.cidarlab.eugene.exception.EugeneException; /** - * A ComponentType represents an abstract genetic component, such as part type. - * In Eugene, every Component has a ComponentType. A ComponentType has a list of + * A ComponentType represents an abstract genetic component, such as part type. + * In Eugene, every Component has a ComponentType. A ComponentType has a list of * properties that the Component instantiates (so-called Property Values). - * + * * @author Ernst Oberortner * */ -public class ComponentType - extends NamedElement { +public class ComponentType + extends NamedElement { - private static final long serialVersionUID = 1242448556255896751L; + private static final long serialVersionUID = 1242448556255896751L; - /* + /* * LIST OF PROPERTIES * * Every ComponentType has two pre-defined properties: PIGEON and SEQUENCE * both pre-defined properties are appended at the * end of the user-defined list of properties. * - */ - protected List properties; - - /** - * Constructor w/ name - * - * @param name ... the name of the ComponentType - */ - protected ComponentType(String name) { - super(name); - this.properties = new ArrayList(); - - this.addPredefinedProperties(); - } - - private void addPredefinedProperties() { - /* + */ + protected List properties; + + /** + * Constructor w/ name + * + * @param name ... the name of the ComponentType + */ + protected ComponentType(String name) { + super(name); + this.properties = new ArrayList(); + + this.addPredefinedProperties(); + } + + private void addPredefinedProperties() { + /* * check if the list of properties contains - * the PIGEON and SEQUENCE Property - */ - boolean bPigeon = false; - boolean bSequence = false; - for(Property prop : this.getProperties()) { - if(EugeneConstants.SEQUENCE_PROPERTY.equals(prop.getName().toUpperCase())) { - bSequence = true; - } else if(EugeneConstants.PIGEON_PROPERTY.equals(prop.getName().toUpperCase())) { - bPigeon = true; - } - } - - if(!bPigeon) { - this.properties.add( - new Property(EugeneConstants.PIGEON_PROPERTY, EugeneConstants.TXT)); - } - - if(!bSequence) { - this.properties.add( - new Property(EugeneConstants.SEQUENCE_PROPERTY, EugeneConstants.TXT)); - } - } - - /** - * Constructor w/ name and properties - * - * @param name ... the name of the ComponentType - * @param properties ... a list of properties of the type - */ - public ComponentType(String name, List properties) { - super(name); - this.properties = properties; - - this.addPredefinedProperties(); - } - - - /** - * The getProperties() method returns the list of properties - * of the ComponentType - * - * @return the of the ComponentType's properties - */ - public List getProperties() { - return this.properties; - } - - /** - * The getProperty(String) method returns a property of - * a given name. If the property does not exist, then - * it returns NULL. - * - * @param name ... the name of the desired Property - * @return ... the Property if it exists, NULL otherwise - */ - public Property getProperty(String name) { - - for (Property p : this.getProperties()) { - if (p.getName().equals(name)) { - return p; - } - } - - return (Property) null; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Type ").append(this.getName()).append("("); - for(int i=0; i requiredProps = Arrays.asList( + EugeneConstants.SEQUENCE_ONTOLOGY_PROPERTY, + EugeneConstants.PIGEON_PROPERTY, + EugeneConstants.SEQUENCE_PROPERTY); + + List props = this.getPropertyNames(); + + for (String rProp : requiredProps) { + if (!props.contains(rProp)) { + this.properties.add(new Property(rProp, EugeneConstants.TXT)); + } + } + } + + /** + * Constructor w/ name and properties + * + * @param name ... the name of the ComponentType + * @param properties ... a list of properties of the type + */ + public ComponentType(String name, List properties) { + super(name); + this.properties = properties; + + this.addPredefinedProperties(); + } + + /** + * The getProperties() method returns the list of properties of the + * ComponentType + * + * @return the of the ComponentType's properties + */ + public List getProperties() { + return this.properties; + } + + /** + * The getProperty(String) method returns a property of a given name. If the + * property does not exist, then it returns NULL. + * + * @param name ... the name of the desired Property + * @return ... the Property if it exists, NULL otherwise + */ + public Property getProperty(String name) { + + for (Property p : this.getProperties()) { + if (p.getName().equals(name)) { + return p; + } + } + + return (Property) null; + } + + /** + * The getProperties() method returns the list of properties of the + * ComponentType + * + * @return the of the ComponentType's properties + */ + public List getPropertyNames() { + + List names = new ArrayList<>(); + + for (Property prop : this.getProperties()) { + names.add(prop.getName()); + } + + return names; + + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Type ").append(this.getName()).append("("); + for (int i = 0; i < this.getProperties().size(); i++) { + sb.append(".").append(this.getProperties().get(i).getName()).append("(") + .append(this.getProperties().get(i).getType()).append(")"); + + if (i < this.getProperties().size() - 1) { + sb.append(", "); + } + } + sb.append(");"); + return sb.toString(); + } + + @Override + public NamedElement getElement(String name) { + /* * here, we iterate over the properties - */ - return this.getProperty(name); - } - - @Override - public NamedElement getElement(int idx) - throws EugeneException { - if(idx < 0 || idx >= this.getProperties().size()) { - throw new EugeneException(idx + " is out of bounds in the " + this.getName() +" type!"); - } - return this.getProperties().get(idx); - } + */ + return this.getProperty(name); + } + + @Override + public NamedElement getElement(int idx) + throws EugeneException { + if (idx < 0 || idx >= this.getProperties().size()) { + throw new EugeneException(idx + " is out of bounds in the " + this.getName() + " type!"); + } + return this.getProperties().get(idx); + } } diff --git a/src/test/java/org/cidarlab/eugene/units/DeclarationsTest.java b/src/test/java/org/cidarlab/eugene/units/DeclarationsTest.java index 2c31b79..2f35378 100644 --- a/src/test/java/org/cidarlab/eugene/units/DeclarationsTest.java +++ b/src/test/java/org/cidarlab/eugene/units/DeclarationsTest.java @@ -26,7 +26,6 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - package org.cidarlab.eugene.units; import static org.junit.Assert.*; @@ -49,22 +48,22 @@ public class DeclarationsTest { - private Eugene eugene; - - @Before - public void setUp() - throws Exception { - this.eugene = new Eugene(); - } - - @After - public void tearDown() - throws Exception { - - this.eugene = null; - } - - /*--------------------------------------- + private Eugene eugene; + + @Before + public void setUp() + throws Exception { + this.eugene = new Eugene(); + } + + @After + public void tearDown() + throws Exception { + + this.eugene = null; + } + + /*--------------------------------------- * PROPERTY DECLARATIONS * we test all 5 types of properties (num, num[], txt, txt[], bool) * @@ -78,114 +77,114 @@ public void tearDown() * - name of property * - type of property *---------------------------------------*/ - @Test - public void testNumPropertyDeclaration() { - - Property num_prop = new Property("num_prop", EugeneConstants.NUM); - - String script = "Property num_prop(num);"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - - assertTrue(col.get("num_prop") != null); - assertTrue(col.get("num_prop") instanceof Property); - assertTrue(col.get("num_prop").getName().equals(num_prop.getName())); - assertTrue(((Property)col.get("num_prop")).getType().equals(num_prop.getType())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testTxtPropertyDeclaration() { - Property txt_prop = new Property("txt_prop", EugeneConstants.TXT); - - String script = "Property txt_prop(txt);"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - assertTrue(col.get("txt_prop") != null); - assertTrue(col.get("txt_prop") instanceof Property); - assertTrue(col.get("txt_prop").getName().equals(txt_prop.getName())); - - assertTrue(((Property)col.get("txt_prop")).getType().equals(txt_prop.getType())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testBoolPropertyDeclaration() { - Property bool_prop = new Property("bool_prop", EugeneConstants.BOOLEAN); - - String script = "Property bool_prop(bool);"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - assertTrue(col.get("bool_prop") != null); - assertTrue(col.get("bool_prop") instanceof Property); - assertTrue(col.get("bool_prop").getName().equals(bool_prop.getName())); - - assertTrue(((Property)col.get("bool_prop")).getType().equals(bool_prop.getType())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testTxtListPropertyDeclaration() { - Property txt_list_prop = new Property("txt_list_prop", EugeneConstants.TXTLIST); - - String script = "Property txt_list_prop(txt[]);"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - assertTrue(col.get("txt_list_prop") != null); - assertTrue(col.get("txt_list_prop") instanceof Property); - assertTrue(col.get("txt_list_prop").getName().equals(txt_list_prop.getName())); - - assertTrue(((Property)col.get("txt_list_prop")).getType().equals(txt_list_prop.getType())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testNumListPropertyDeclaration() { - Property num_list_prop = new Property("num_list_prop", EugeneConstants.NUMLIST); - - String script = "Property num_list_prop(num[]);"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - assertTrue(col.get("num_list_prop") != null); - assertTrue(col.get("num_list_prop") instanceof Property); - assertTrue(col.get("num_list_prop").getName().equals(num_list_prop.getName())); - - assertTrue(((Property)col.get("num_list_prop")).getType().equals(num_list_prop.getType())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - /*--------------------------------------- + @Test + public void testNumPropertyDeclaration() { + + Property num_prop = new Property("num_prop", EugeneConstants.NUM); + + String script = "Property num_prop(num);"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + + assertTrue(col.get("num_prop") != null); + assertTrue(col.get("num_prop") instanceof Property); + assertTrue(col.get("num_prop").getName().equals(num_prop.getName())); + assertTrue(((Property) col.get("num_prop")).getType().equals(num_prop.getType())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testTxtPropertyDeclaration() { + Property txt_prop = new Property("txt_prop", EugeneConstants.TXT); + + String script = "Property txt_prop(txt);"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + assertTrue(col.get("txt_prop") != null); + assertTrue(col.get("txt_prop") instanceof Property); + assertTrue(col.get("txt_prop").getName().equals(txt_prop.getName())); + + assertTrue(((Property) col.get("txt_prop")).getType().equals(txt_prop.getType())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testBoolPropertyDeclaration() { + Property bool_prop = new Property("bool_prop", EugeneConstants.BOOLEAN); + + String script = "Property bool_prop(bool);"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + assertTrue(col.get("bool_prop") != null); + assertTrue(col.get("bool_prop") instanceof Property); + assertTrue(col.get("bool_prop").getName().equals(bool_prop.getName())); + + assertTrue(((Property) col.get("bool_prop")).getType().equals(bool_prop.getType())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testTxtListPropertyDeclaration() { + Property txt_list_prop = new Property("txt_list_prop", EugeneConstants.TXTLIST); + + String script = "Property txt_list_prop(txt[]);"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + assertTrue(col.get("txt_list_prop") != null); + assertTrue(col.get("txt_list_prop") instanceof Property); + assertTrue(col.get("txt_list_prop").getName().equals(txt_list_prop.getName())); + + assertTrue(((Property) col.get("txt_list_prop")).getType().equals(txt_list_prop.getType())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testNumListPropertyDeclaration() { + Property num_list_prop = new Property("num_list_prop", EugeneConstants.NUMLIST); + + String script = "Property num_list_prop(num[]);"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + assertTrue(col.get("num_list_prop") != null); + assertTrue(col.get("num_list_prop") instanceof Property); + assertTrue(col.get("num_list_prop").getName().equals(num_list_prop.getName())); + + assertTrue(((Property) col.get("num_list_prop")).getType().equals(num_list_prop.getType())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + /*--------------------------------------- * PART TYPE DECLARATIONS * * Test Strategy: @@ -197,112 +196,113 @@ public void testNumListPropertyDeclaration() { * - PartType class * - name of part type * - list of properties - *---------------------------------------*/ - @Test - public void testEmptyPartTypeDeclaration() { - PartType empty = new PartType("empty"); - - String script = "PartType empty();"; - - try { - EugeneCollection col = this.eugene.executeScript(script); - assertTrue(col != null); - assertTrue(col.getElements().size() == 1); - assertTrue(col.get("empty") != null); - assertTrue(col.get("empty") instanceof PartType); - assertTrue(col.get("empty").getName().equals(empty.getName())); - - assertTrue(((PartType)col.get("empty")).getProperties().equals(empty.getProperties())); - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testPartTypeWithOnePropertyDeclaration() { - Property prop = new Property("prop", EugeneConstants.TXT); - PartType pt_one = new PartType("pt_one"); - pt_one.getProperties().add(prop); - - String script = "Property prop(txt); PartType pt_one(prop);"; - - try { - EugeneCollection ec = this.eugene.executeScript(script); - assertTrue(null != ec); - // 2 elements: prop, pt_one - assertTrue(ec.getElements().size() == 2); - - assertTrue(null != ec.get("prop")); - assertTrue(ec.get("prop") instanceof Property); - - assertTrue(null != ec.get("pt_one")); - assertTrue(ec.get("pt_one") instanceof PartType); - - assertTrue(((PartType)ec.get("pt_one")).getProperty("prop").equals(ec.get("prop"))); - - } catch(EugeneException ee) { - ee.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testPartTypeWithManyPropertiesDeclaration() { - int NR_PROPERTIES = 100; - PartType pt_many = new PartType("pt_many"); - - StringBuilder sbProps = new StringBuilder(); - StringBuilder sbPropAssign = new StringBuilder(); - for(int i=1; i<=NR_PROPERTIES; i++) { - - // assigning property to part type - pt_many.getProperties().add( - new Property("prop", EugeneConstants.TXT)); - - // building script - sbProps.append("Property prop"+i+"(txt);"); - - sbPropAssign.append("prop"+i); - if(i<=NR_PROPERTIES-1) { - sbPropAssign.append(","); - } - - } - - StringBuilder script = new StringBuilder(); - script.append(sbProps.toString()) - .append("PartType pt_many(") - .append(sbPropAssign) - .append(");"); - - - try { - EugeneCollection ec = this.eugene.executeScript(script.toString()); - - assertTrue(null != ec); - // 2 elements: prop, pt_one - assertTrue(ec.getElements().size() == NR_PROPERTIES + 1); - - for(int i=1; i<=NR_PROPERTIES; i++) { - assertTrue(null != ec.get("prop"+i)); - assertTrue(ec.get("prop"+i) instanceof Property); - } - - assertTrue(null != ec.get("pt_many")); - assertTrue(ec.get("pt_many") instanceof PartType); - assertTrue(((PartType)ec.get("pt_many")).getProperties().size() == NR_PROPERTIES + 2); - // +2 ... SEQUENCE and PIGEON property - + *---------------------------------------*/ + @Test + public void testEmptyPartTypeDeclaration() { + PartType empty = new PartType("empty"); + + String script = "PartType empty();"; + + try { + EugeneCollection col = this.eugene.executeScript(script); + assertTrue(col != null); + assertTrue(col.getElements().size() == 1); + assertTrue(col.get("empty") != null); + assertTrue(col.get("empty") instanceof PartType); + assertTrue(col.get("empty").getName().equals(empty.getName())); + + assertTrue(((PartType) col.get("empty")).getProperties().equals(empty.getProperties())); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testPartTypeWithOnePropertyDeclaration() { + Property prop = new Property("prop", EugeneConstants.TXT); + PartType pt_one = new PartType("pt_one"); + pt_one.getProperties().add(prop); + + String script = "Property prop(txt); PartType pt_one(prop);"; + + try { + EugeneCollection ec = this.eugene.executeScript(script); + assertTrue(null != ec); + // 2 elements: prop, pt_one + assertTrue(ec.getElements().size() == 2); + + assertTrue(null != ec.get("prop")); + assertTrue(ec.get("prop") instanceof Property); + + assertTrue(null != ec.get("pt_one")); + assertTrue(ec.get("pt_one") instanceof PartType); + + assertTrue(((PartType) ec.get("pt_one")).getProperty("prop").equals(ec.get("prop"))); + + } catch (EugeneException ee) { + ee.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testPartTypeWithManyPropertiesDeclaration() { + int NR_PROPERTIES = 100; + int NR_REQUIRED_PROPERTIES = 3; //SEQUENCE, PIGEON, SEQUENCE_ONTOLOGY_PROPERTY + + PartType pt_many = new PartType("pt_many"); + + StringBuilder sbProps = new StringBuilder(); + StringBuilder sbPropAssign = new StringBuilder(); + for (int i = 1; i <= NR_PROPERTIES; i++) { + + // assigning property to part type + pt_many.getProperties().add( + new Property("prop", EugeneConstants.TXT)); + + // building script + sbProps.append("Property prop" + i + "(txt);"); + + sbPropAssign.append("prop" + i); + if (i <= NR_PROPERTIES - 1) { + sbPropAssign.append(","); + } + + } + + StringBuilder script = new StringBuilder(); + script.append(sbProps.toString()) + .append("PartType pt_many(") + .append(sbPropAssign) + .append(");"); + + try { + EugeneCollection ec = this.eugene.executeScript(script.toString()); + + assertTrue(null != ec); + // 2 elements: prop, pt_one + assertTrue(ec.getElements().size() == NR_PROPERTIES + 1); + + for (int i = 1; i <= NR_PROPERTIES; i++) { + assertTrue(null != ec.get("prop" + i)); + assertTrue(ec.get("prop" + i) instanceof Property); + } + + assertTrue(null != ec.get("pt_many")); + assertTrue(ec.get("pt_many") instanceof PartType); + + assertTrue(((PartType) ec.get("pt_many")).getProperties().size() == NR_PROPERTIES + NR_REQUIRED_PROPERTIES); + // +3 ... SEQUENCE, PIGEON, and SEQUENCE_ONTOLOGY_PROPERTY + // assertTrue(((PartType)ec.get("pt_one")).getProperty("prop").equals(ec.get("prop"))); - - } catch(EugeneException ee) { - ee.printStackTrace(); - assertTrue(false); - } - } - - /*--------------------------------------- + } catch (EugeneException ee) { + ee.printStackTrace(); + assertTrue(false); + } + } + + /*--------------------------------------- * INSTANTIATIONS (OF PART TYPES) * * Test Strategy: @@ -315,270 +315,266 @@ public void testPartTypeWithManyPropertiesDeclaration() { * - PartType class * - name of part type * - list of properties - *---------------------------------------*/ - @Test - public void testInstantiation() { - - // properties - Property num_prop = new Property("num_prop", EugeneConstants.NUM); - Property txt_prop = new Property("txt_prop", EugeneConstants.TXT); - - // part types - PartType PT = new PartType("PT"); - PT.getProperties().add(num_prop); - PT.getProperties().add(txt_prop); - - // parts - Part pt_p1 = new Part("pt_p1", PT); - PropertyValue pt_p1_num = new PropertyValue(num_prop); - pt_p1_num.setNum(1); - try { - pt_p1.setPropertyValue(num_prop, pt_p1_num); - } catch(DOMException de) { - assertTrue(false); - } - PropertyValue pt_p1_txt = new PropertyValue(txt_prop); - pt_p1_txt.setTxt("one"); - try { - pt_p1.setPropertyValue(txt_prop, pt_p1_txt); - } catch(DOMException de) { - assertTrue(false); - } - - - Part pt_p2 = new Part("pt_p2", PT); - PropertyValue pt_p2_num = new PropertyValue(num_prop); - pt_p2_num.setNum(2); - try { - pt_p2.setPropertyValue(num_prop, pt_p2_num); - } catch(DOMException de) { - assertTrue(false); - } - PropertyValue pt_p2_txt = new PropertyValue(txt_prop); - pt_p2_txt.setTxt("two"); - try { - pt_p2.setPropertyValue(txt_prop, pt_p2_txt); - } catch(DOMException de) { - assertTrue(false); - } - - - String script = - "Property num_prop(num); Property txt_prop(txt); " + - "PartType PT(num_prop, txt_prop); " + - "PT pt_p1(.num_prop(1), .txt_prop(\"one\")); " + - "PT pt_p2(.num_prop(2), .txt_prop(\"two\")); "; - - try { - EugeneCollection ec = this.eugene.executeScript(script.toString()); - - // pt_p1.pt_p1_num - assertTrue(ec.get("pt_p1") instanceof Part); - - assertTrue(((Part)ec.get("pt_p1")).getPropertyValue("num_prop") != null); - assertTrue(EugeneConstants.NUM.equals( - ((Part)ec.get("pt_p1")).getPropertyValue("num_prop").getType())); - assertTrue(1 == ((Part)ec.get("pt_p1")).getPropertyValue("num_prop").getNum()); - - // pt_p1.pt_p1_txt - assertTrue(ec.get("pt_p1") instanceof Part); - assertTrue(((Part)ec.get("pt_p1")).getPropertyValue("txt_prop") != null); - assertTrue(EugeneConstants.TXT.equals( - ((Part)ec.get("pt_p1")).getPropertyValue("txt_prop").getType())); - assertTrue("one".equals(((Part)ec.get("pt_p1")).getPropertyValue("txt_prop").getTxt())); - - // pt_p2.pt_p2_num - assertTrue(ec.get("pt_p2") instanceof Part); - assertTrue(((Part)ec.get("pt_p2")).getPropertyValue("num_prop") != null); - assertTrue(EugeneConstants.NUM.equals( - ((Part)ec.get("pt_p2")).getPropertyValue("num_prop").getType())); - assertTrue(2 == ((Part)ec.get("pt_p2")).getPropertyValue("num_prop").getNum()); - - // pt_p2.pt_p2_txt - assertTrue(ec.get("pt_p2") instanceof Part); - assertTrue(((Part)ec.get("pt_p2")).getPropertyValue("txt_prop") != null); - assertTrue(EugeneConstants.TXT.equals( - ((Part)ec.get("pt_p2")).getPropertyValue("txt_prop").getType())); - assertTrue("two".equals(((Part)ec.get("pt_p2")).getPropertyValue("txt_prop").getTxt())); - - } catch(EugeneException ee) { - assertTrue(false); - } - } - - @Test - public void testPartSequenceProperty() { - - String seq = "ATCG"; - - PartType PT = new PartType("PT"); - Part p1 = new Part(PT, "p1"); - p1.setSequence(seq); - - try { - - assertTrue(seq.equals(p1.getPropertyValue(EugeneConstants.SEQUENCE_PROPERTY).getTxt())); - - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } - - @Test - public void testPartPigeonProperty() { - - String pig = "p p1 1 nl"; - - PartType PT = new PartType("PT"); - Part p1 = new Part(PT, "p1"); - - Property pigProp = EugeneDeveloperUtils.createPigeonProperty(); - PropertyValue pigVal = new PropertyValue(pigProp); - pigVal.setTxt(pig); - - try { - - p1.setPropertyValue(pigProp, pigVal); - - assertTrue(pig.equals(p1.getPropertyValue(EugeneConstants.PIGEON_PROPERTY).getTxt())); - - } catch(Exception e) { - e.printStackTrace(); - assertTrue(false); - } - - - } - - @Test - public void testNotDeclared_device_product() { - String script = "Device D; product(X);"; - - try { - new Eugene().executeScript(script); - } catch(EugeneException ee) { - assertTrue(ee.getMessage().contains("X is not declared.")); - } - } - - @Test - public void testNotDevice_product() { - String script = "num i; Device D; product(i);"; - - try { - new Eugene().executeScript(script); - } catch(EugeneException ee) { - assertTrue(ee.getMessage().contains("i is not a Device.")); - } - } - - /*---------------------------- + *---------------------------------------*/ + @Test + public void testInstantiation() { + + // properties + Property num_prop = new Property("num_prop", EugeneConstants.NUM); + Property txt_prop = new Property("txt_prop", EugeneConstants.TXT); + + // part types + PartType PT = new PartType("PT"); + PT.getProperties().add(num_prop); + PT.getProperties().add(txt_prop); + + // parts + Part pt_p1 = new Part("pt_p1", PT); + PropertyValue pt_p1_num = new PropertyValue(num_prop); + pt_p1_num.setNum(1); + try { + pt_p1.setPropertyValue(num_prop, pt_p1_num); + } catch (DOMException de) { + assertTrue(false); + } + PropertyValue pt_p1_txt = new PropertyValue(txt_prop); + pt_p1_txt.setTxt("one"); + try { + pt_p1.setPropertyValue(txt_prop, pt_p1_txt); + } catch (DOMException de) { + assertTrue(false); + } + + Part pt_p2 = new Part("pt_p2", PT); + PropertyValue pt_p2_num = new PropertyValue(num_prop); + pt_p2_num.setNum(2); + try { + pt_p2.setPropertyValue(num_prop, pt_p2_num); + } catch (DOMException de) { + assertTrue(false); + } + PropertyValue pt_p2_txt = new PropertyValue(txt_prop); + pt_p2_txt.setTxt("two"); + try { + pt_p2.setPropertyValue(txt_prop, pt_p2_txt); + } catch (DOMException de) { + assertTrue(false); + } + + String script + = "Property num_prop(num); Property txt_prop(txt); " + + "PartType PT(num_prop, txt_prop); " + + "PT pt_p1(.num_prop(1), .txt_prop(\"one\")); " + + "PT pt_p2(.num_prop(2), .txt_prop(\"two\")); "; + + try { + EugeneCollection ec = this.eugene.executeScript(script.toString()); + + // pt_p1.pt_p1_num + assertTrue(ec.get("pt_p1") instanceof Part); + + assertTrue(((Part) ec.get("pt_p1")).getPropertyValue("num_prop") != null); + assertTrue(EugeneConstants.NUM.equals( + ((Part) ec.get("pt_p1")).getPropertyValue("num_prop").getType())); + assertTrue(1 == ((Part) ec.get("pt_p1")).getPropertyValue("num_prop").getNum()); + + // pt_p1.pt_p1_txt + assertTrue(ec.get("pt_p1") instanceof Part); + assertTrue(((Part) ec.get("pt_p1")).getPropertyValue("txt_prop") != null); + assertTrue(EugeneConstants.TXT.equals( + ((Part) ec.get("pt_p1")).getPropertyValue("txt_prop").getType())); + assertTrue("one".equals(((Part) ec.get("pt_p1")).getPropertyValue("txt_prop").getTxt())); + + // pt_p2.pt_p2_num + assertTrue(ec.get("pt_p2") instanceof Part); + assertTrue(((Part) ec.get("pt_p2")).getPropertyValue("num_prop") != null); + assertTrue(EugeneConstants.NUM.equals( + ((Part) ec.get("pt_p2")).getPropertyValue("num_prop").getType())); + assertTrue(2 == ((Part) ec.get("pt_p2")).getPropertyValue("num_prop").getNum()); + + // pt_p2.pt_p2_txt + assertTrue(ec.get("pt_p2") instanceof Part); + assertTrue(((Part) ec.get("pt_p2")).getPropertyValue("txt_prop") != null); + assertTrue(EugeneConstants.TXT.equals( + ((Part) ec.get("pt_p2")).getPropertyValue("txt_prop").getType())); + assertTrue("two".equals(((Part) ec.get("pt_p2")).getPropertyValue("txt_prop").getTxt())); + + } catch (EugeneException ee) { + assertTrue(false); + } + } + + @Test + public void testPartSequenceProperty() { + + String seq = "ATCG"; + + PartType PT = new PartType("PT"); + Part p1 = new Part(PT, "p1"); + p1.setSequence(seq); + + try { + + assertTrue(seq.equals(p1.getPropertyValue(EugeneConstants.SEQUENCE_PROPERTY).getTxt())); + + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + // TO DO: VALIDATE BLANK SO NUMBERS + @Test + public void testPartPigeonProperty() { + + String pig = "p p1 1 nl"; + + PartType PT = new PartType("PT"); + Part p1 = new Part(PT, "p1"); + + Property pigProp = EugeneDeveloperUtils.createPigeonProperty(); + PropertyValue pigVal = new PropertyValue(pigProp); + pigVal.setTxt(pig); + + try { + + p1.setPropertyValue(pigProp, pigVal); + + assertTrue(pig.equals(p1.getPropertyValue(EugeneConstants.PIGEON_PROPERTY).getTxt())); + + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + + } + + @Test + public void testNotDeclared_device_product() { + String script = "Device D; product(X);"; + + try { + new Eugene().executeScript(script); + } catch (EugeneException ee) { + assertTrue(ee.getMessage().contains("X is not declared.")); + } + } + + @Test + public void testNotDevice_product() { + String script = "num i; Device D; product(i);"; + + try { + new Eugene().executeScript(script); + } catch (EugeneException ee) { + assertTrue(ee.getMessage().contains("i is not a Device.")); + } + } + + /*---------------------------- * COMPOSITE BIOLOGICAL FACTS * * Section 3.1.4 *----------------------------*/ - - @Test - public void testCompositeDevice_orientations() { - String script = - "PartType Promoter(); " + - "Promoter I14018; " + - "Device proms(I14018, I14018); " + - "Device fproms(+I14018, +I14018); " + - "Device rproms(-I14018, -I14018); " + - "Device hierarchical(proms, +I14018); "; - - try { - EugeneCollection ec = new Eugene().executeScript(script); - - assertTrue(null != ec); - - /*------- + @Test + public void testCompositeDevice_orientations() { + String script + = "PartType Promoter(); " + + "Promoter I14018; " + + "Device proms(I14018, I14018); " + + "Device fproms(+I14018, +I14018); " + + "Device rproms(-I14018, -I14018); " + + "Device hierarchical(proms, +I14018); "; + + try { + EugeneCollection ec = new Eugene().executeScript(script); + + assertTrue(null != ec); + + /*------- * proms Device *-------*/ - assertTrue(null != ec.get("proms")); - assertTrue(ec.get("proms") instanceof Device); - Device proms = (Device)ec.get("proms"); - assertTrue(null != proms.getOrientations()); - assertTrue(proms.getOrientations().size() == 2); - assertTrue(null != proms.getOrientations(0)); - assertTrue(proms.getOrientations(0).size() == 1); - assertTrue(proms.getOrientations(0).get(0) == Orientation.UNDEFINED); - assertTrue(null != proms.getOrientations(1)); - assertTrue(proms.getOrientations(1).size() == 1); - assertTrue(proms.getOrientations(1).get(0) == Orientation.UNDEFINED); - - /*------- + assertTrue(null != ec.get("proms")); + assertTrue(ec.get("proms") instanceof Device); + Device proms = (Device) ec.get("proms"); + assertTrue(null != proms.getOrientations()); + assertTrue(proms.getOrientations().size() == 2); + assertTrue(null != proms.getOrientations(0)); + assertTrue(proms.getOrientations(0).size() == 1); + assertTrue(proms.getOrientations(0).get(0) == Orientation.UNDEFINED); + assertTrue(null != proms.getOrientations(1)); + assertTrue(proms.getOrientations(1).size() == 1); + assertTrue(proms.getOrientations(1).get(0) == Orientation.UNDEFINED); + + /*------- * fproms Device *-------*/ - assertTrue(null != ec.get("fproms")); - assertTrue(ec.get("fproms") instanceof Device); - Device fproms = (Device)ec.get("fproms"); - assertTrue(null != fproms.getOrientations()); - assertTrue(fproms.getOrientations().size() == 2); - assertTrue(null != fproms.getOrientations(0)); - assertTrue(fproms.getOrientations(0).size() == 1); - assertTrue(fproms.getOrientations(0).get(0) == Orientation.FORWARD); - assertTrue(null != fproms.getOrientations(1)); - assertTrue(fproms.getOrientations(1).size() == 1); - assertTrue(fproms.getOrientations(1).get(0) == Orientation.FORWARD); - - /*------- + assertTrue(null != ec.get("fproms")); + assertTrue(ec.get("fproms") instanceof Device); + Device fproms = (Device) ec.get("fproms"); + assertTrue(null != fproms.getOrientations()); + assertTrue(fproms.getOrientations().size() == 2); + assertTrue(null != fproms.getOrientations(0)); + assertTrue(fproms.getOrientations(0).size() == 1); + assertTrue(fproms.getOrientations(0).get(0) == Orientation.FORWARD); + assertTrue(null != fproms.getOrientations(1)); + assertTrue(fproms.getOrientations(1).size() == 1); + assertTrue(fproms.getOrientations(1).get(0) == Orientation.FORWARD); + + /*------- * rproms Device *-------*/ - assertTrue(null != ec.get("rproms")); - assertTrue(ec.get("rproms") instanceof Device); - Device rproms = (Device)ec.get("rproms"); - assertTrue(null != rproms.getOrientations()); - assertTrue(rproms.getOrientations().size() == 2); - assertTrue(null != rproms.getOrientations(0)); - assertTrue(rproms.getOrientations(0).size() == 1); - assertTrue(rproms.getOrientations(0).get(0) == Orientation.REVERSE); - assertTrue(null != rproms.getOrientations(1)); - assertTrue(rproms.getOrientations(1).size() == 1); - assertTrue(rproms.getOrientations(1).get(0) == Orientation.REVERSE); - - /*------- + assertTrue(null != ec.get("rproms")); + assertTrue(ec.get("rproms") instanceof Device); + Device rproms = (Device) ec.get("rproms"); + assertTrue(null != rproms.getOrientations()); + assertTrue(rproms.getOrientations().size() == 2); + assertTrue(null != rproms.getOrientations(0)); + assertTrue(rproms.getOrientations(0).size() == 1); + assertTrue(rproms.getOrientations(0).get(0) == Orientation.REVERSE); + assertTrue(null != rproms.getOrientations(1)); + assertTrue(rproms.getOrientations(1).size() == 1); + assertTrue(rproms.getOrientations(1).get(0) == Orientation.REVERSE); + + /*------- * hierarchical Device *-------*/ - assertTrue(null != ec.get("hierarchical")); - assertTrue(ec.get("hierarchical") instanceof Device); - Device hierarchical = (Device)ec.get("hierarchical"); - assertTrue(null != hierarchical.getOrientations()); - assertTrue(hierarchical.getOrientations().size() == 2); - assertTrue(null != hierarchical.getOrientations(0)); - assertTrue(hierarchical.getOrientations(0).size() == 1); - assertTrue(hierarchical.getOrientations(0).get(0) == Orientation.UNDEFINED); - assertTrue(null != hierarchical.getOrientations(1)); - assertTrue(hierarchical.getOrientations(1).size() == 1); - assertTrue(hierarchical.getOrientations(1).get(0) == Orientation.FORWARD); - } catch(EugeneException ee) { - // no exception allowed here - assertTrue(false); - } - - } - - /*---------------------------- + assertTrue(null != ec.get("hierarchical")); + assertTrue(ec.get("hierarchical") instanceof Device); + Device hierarchical = (Device) ec.get("hierarchical"); + assertTrue(null != hierarchical.getOrientations()); + assertTrue(hierarchical.getOrientations().size() == 2); + assertTrue(null != hierarchical.getOrientations(0)); + assertTrue(hierarchical.getOrientations(0).size() == 1); + assertTrue(hierarchical.getOrientations(0).get(0) == Orientation.UNDEFINED); + assertTrue(null != hierarchical.getOrientations(1)); + assertTrue(hierarchical.getOrientations(1).size() == 1); + assertTrue(hierarchical.getOrientations(1).get(0) == Orientation.FORWARD); + } catch (EugeneException ee) { + // no exception allowed here + assertTrue(false); + } + + } + + /*---------------------------- * COMPOSITE BIOLOGICAL FACTS * * Section 3.1.4 *----------------------------*/ - - @Test - public void testInteractions_represses() { - String script = - "PartType Promoter(); " + - "PartType Repressor(); " + - "Repressor r1; Repressor r2; Repressor r3; " + - "Promoter p1; Promoter p2; Promoter p3; " + - "r1 REPRESSES p1; r2 represses p2; r3 REPRESSES p3; "; - try { - new Eugene().executeScript(script); - } catch(EugeneException ee) { - ee.printStackTrace(); - assertTrue(false); - } - } + @Test + public void testInteractions_represses() { + String script + = "PartType Promoter(); " + + "PartType Repressor(); " + + "Repressor r1; Repressor r2; Repressor r3; " + + "Promoter p1; Promoter p2; Promoter p3; " + + "r1 REPRESSES p1; r2 represses p2; r3 REPRESSES p3; "; + try { + new Eugene().executeScript(script); + } catch (EugeneException ee) { + ee.printStackTrace(); + assertTrue(false); + } + } }