212 lines
6.7 KiB
Java
212 lines
6.7 KiB
Java
package src.fr.test;
|
|
|
|
import java.util.Set;
|
|
import java.util.HashSet;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import src.fr.impl.*;
|
|
import src.fr.impl.Parts.*;
|
|
import src.fr.api.*;
|
|
|
|
public class test_V2 {
|
|
CategoryImpl engine = new CategoryImpl("Engine");
|
|
CategoryImpl transmission = new CategoryImpl("Transmission");
|
|
CategoryImpl exterior = new CategoryImpl("Exterior");
|
|
CategoryImpl interior = new CategoryImpl("Interior");
|
|
|
|
//PartType
|
|
PartType EG100= new PartTypeImpl("EG100",Engine.class, engine);
|
|
PartType EG133= new PartTypeImpl("EG133",Engine.class, engine);
|
|
PartType EG210= new PartTypeImpl("EG210",Engine.class, engine);
|
|
PartType ED110= new PartTypeImpl("ED110",Engine.class, engine);
|
|
PartType ED180= new PartTypeImpl("ED180",Engine.class, engine);
|
|
PartType EH120= new PartTypeImpl("EH120",Engine.class, engine);
|
|
|
|
PartType TM5= new PartTypeImpl("TM5", Transmission.class ,transmission);
|
|
PartType TM6= new PartTypeImpl("TM6", Transmission.class ,transmission);
|
|
PartType TA5= new PartTypeImpl("TA5", Transmission.class ,transmission);
|
|
PartType TS6= new PartTypeImpl("TS6", Transmission.class ,transmission);
|
|
PartType TSF7= new PartTypeImpl("TSF7", Transmission.class ,transmission);
|
|
PartType TC120= new PartTypeImpl("TC120", Transmission.class ,transmission);
|
|
|
|
PartType XC= new PartTypeImpl("XC", Exterior.class,exterior);
|
|
PartType XM= new PartTypeImpl("XM", Exterior.class,exterior);
|
|
PartType XS= new PartTypeImpl("XS", Exterior.class,exterior);
|
|
|
|
PartType IN= new PartTypeImpl("IN", Interior.class ,interior);
|
|
PartType IH= new PartTypeImpl("IH", Interior.class ,interior);
|
|
PartType IS= new PartTypeImpl("IS", Interior.class ,interior);
|
|
|
|
CompatibilityManager cm = new CompatibilityManagerImpl();
|
|
|
|
|
|
@Before
|
|
public void init(){
|
|
Set<PartType> EH120Requirement = new HashSet<PartType>();
|
|
EH120Requirement.add(TC120);
|
|
|
|
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
|
|
TA5Incompatibilities.add(EG100);
|
|
|
|
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
|
|
TSF7Incompatibilities.add(EG100);
|
|
TSF7Incompatibilities.add(EG133);
|
|
TSF7Incompatibilities.add(ED110);
|
|
|
|
Set<PartType> TC120Requirement = new HashSet<PartType>();
|
|
TC120Requirement.add(EH120);
|
|
|
|
Set<PartType> XCIncompatibilities = new HashSet<PartType>();
|
|
XCIncompatibilities.add(EG210);
|
|
|
|
Set<PartType> XMIncompatibilities = new HashSet<PartType>();
|
|
XMIncompatibilities.add(EG100);
|
|
|
|
Set<PartType> XSIncompatibilities = new HashSet<PartType>();
|
|
XSIncompatibilities.add(EG100);
|
|
Set<PartType> XSRequirement = new HashSet<PartType>();
|
|
XSRequirement.add(IS);
|
|
|
|
Set<PartType> ISIncompatibilities = new HashSet<PartType>();
|
|
ISIncompatibilities.add(EG100);
|
|
ISIncompatibilities.add(TM5);
|
|
Set<PartType> ISRequirement = new HashSet<PartType>();
|
|
ISRequirement.add(XS);
|
|
|
|
cm.addRequirements(EH120, EH120Requirement);
|
|
cm.addIncompatibilities(TA5, TA5Incompatibilities);
|
|
cm.addIncompatibilities(TSF7, TSF7Incompatibilities);
|
|
cm.addRequirements(TC120, TC120Requirement);
|
|
cm.addIncompatibilities(XC, XCIncompatibilities);
|
|
cm.addIncompatibilities(XM, XMIncompatibilities);
|
|
cm.addIncompatibilities(XS, XSIncompatibilities);
|
|
cm.addRequirements(XS, XSRequirement);
|
|
cm.addIncompatibilities(IS, ISIncompatibilities);
|
|
cm.addRequirements(IS, ISRequirement);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void test_isComplete(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TM5);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertTrue(config1.isComplete());
|
|
}
|
|
|
|
@Test
|
|
public void test_isNotComplete(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TM5);
|
|
config1.selectPart(XS);
|
|
|
|
assertFalse(config1.isComplete());
|
|
}
|
|
|
|
@Test
|
|
public void test_isNotComplete_empty_cm(){
|
|
CompatibilityManager cm2 = new CompatibilityManagerImpl();
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm2);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TM5);
|
|
config1.selectPart(XS);
|
|
|
|
assertFalse(config1.isComplete());
|
|
}
|
|
|
|
@Test
|
|
public void test_isValide_empty_cm(){
|
|
CompatibilityManager cm2 = new CompatibilityManagerImpl();
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm2);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TM5);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_isValide1(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void test_isValide2(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
config1.selectPart(TS6);
|
|
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_isNotValide1(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG100);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertFalse(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_isNotValide2(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(XS);
|
|
|
|
assertFalse(config1.isValid());
|
|
}
|
|
|
|
|
|
@Test
|
|
public void test_Property(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
config1.getPart(exterior).setProperty("color","red");
|
|
|
|
assertTrue(config1.getPart(exterior).getProperty("color").get()=="red");
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_NotProperty(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertTrue(config1.getPart(exterior).getProperty("color").isEmpty());
|
|
assertTrue(config1.isValid());
|
|
}
|
|
} |