@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
@Test public void getExpressionElementsWithoutClass() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); assertThatThrownBy(original::getExpressionElementsWithoutClass) .isInstanceOf(IllegalStateException.class) .hasMessage("ExpressionElements malformed"); assertEquals(0, original.getExpressionElements().size()); original.addExpressionElement("STEP", String.class.getCanonicalName()); assertEquals(0, original.getExpressionElementsWithoutClass().size()); assertEquals(1, original.getExpressionElements().size()); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FactMapping that = (FactMapping) o; return getExpressionElements().equals(that.getExpressionElements()) && Objects.equals(getExpressionIdentifier(), that.getExpressionIdentifier()) && Objects.equals(getFactIdentifier(), that.getFactIdentifier()) && Objects.equals(getClassName(), that.getClassName()) && Objects.equals(getFactAlias(), that.getFactAlias()) && Objects.equals(getExpressionAlias(), that.getExpressionAlias()); }
@Test public void getExpressionElementsWithoutClass() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); assertThatThrownBy(original::getExpressionElementsWithoutClass) .isInstanceOf(IllegalStateException.class) .hasMessage("ExpressionElements malformed"); assertEquals(0, original.getExpressionElements().size()); original.addExpressionElement("STEP", String.class.getCanonicalName()); assertEquals(0, original.getExpressionElementsWithoutClass().size()); assertEquals(1, original.getExpressionElements().size()); } }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
@Override public int hashCode() { return Objects.hash(getExpressionElements(), getExpressionIdentifier(), getFactIdentifier(), getClassName(), getFactAlias(), getExpressionAlias()); } }
/** * Returns <code>true</code> when * <p> * instanceAssigned == true * </p><p> * <b>and</b> * </p><p> * !factMapping.getExpressionElements().isEmpty() * </p> * @param instanceAssigned * @param factMapping * @return */ protected boolean isPropertyAssigned(boolean instanceAssigned, FactMapping factMapping) { if (FactIdentifier.DESCRIPTION.equals(factMapping.getFactIdentifier())) { return true; } else { return instanceAssigned && (isSimpleJavaType(factMapping.getClassName()) || !factMapping.getExpressionElements().isEmpty()); } }
@Override public Function<String, String> from1_2to1_3() { return rawXml -> { ScenarioSimulationXMLPersistence xmlPersistence = ScenarioSimulationXMLPersistence.getInstance(); ScenarioSimulationModel model = xmlPersistence.unmarshal(rawXml, false); for (FactMapping factMapping : model.getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { factMapping.getExpressionElements().add(0, new ExpressionElement(factMapping.getFactIdentifier().getName())); } return xmlPersistence.marshal(model).replaceAll("<ScenarioSimulationModel version=\"1.2\">", "<ScenarioSimulationModel version=\"1.3\">"); }; } }
@Test public void isPropertyAssigned() { factMappingDescription.getExpressionElements().clear(); assertTrue(scenarioGrid.isPropertyAssigned(false, factMappingDescription)); assertTrue(scenarioGrid.isPropertyAssigned(true, factMappingDescription)); factMappingDescription.getExpressionElements().add(new ExpressionElement("test")); assertTrue(scenarioGrid.isPropertyAssigned(false, factMappingDescription)); assertTrue(scenarioGrid.isPropertyAssigned(true, factMappingDescription)); factMappingGiven.getExpressionElements().clear(); assertFalse(scenarioGrid.isPropertyAssigned(false, factMappingGiven)); assertFalse(scenarioGrid.isPropertyAssigned(true, factMappingGiven)); factMappingGiven.getExpressionElements().add(new ExpressionElement("test")); assertFalse(scenarioGrid.isPropertyAssigned(false, factMappingGiven)); assertTrue(scenarioGrid.isPropertyAssigned(true, factMappingGiven)); factMappingInteger.getExpressionElements().clear(); assertFalse(scenarioGrid.isPropertyAssigned(false, factMappingInteger)); assertTrue(scenarioGrid.isPropertyAssigned(true, factMappingInteger)); }
@Test public void migrateIfNecessary_1_2_to_1_3() throws Exception { String toMigrate = getFileContent("scesim-1-2.scesim"); String migrated = instance.migrateIfNecessary(toMigrate); assertTrue(toMigrate.contains("<ScenarioSimulationModel version=\"1.2\">")); assertFalse(migrated.contains("<ScenarioSimulationModel version=\"1.2\">")); for (FactMapping factMapping : instance.unmarshal(migrated, false).getSimulation().getSimulationDescriptor().getUnmodifiableFactMappings()) { assertTrue(factMapping.getExpressionElements().size() >= 1); } }