MuleArtifactJsonValidator { protected static void checkMinMuleVersionValue(MuleApplicationModel muleArtifact, List<String> missingFields, Optional<String> deployMuleVersion) throws ValidationException { String minMuleVersionValue = muleArtifact.getMinMuleVersion(); if (StringUtils.isBlank(minMuleVersionValue)) { missingFields.add("minMuleVersion"); } else { isProjectVersionValid(minMuleVersionValue); if (deployMuleVersion != null && deployMuleVersion.isPresent() && StringUtils.isNotBlank(deployMuleVersion.get())) { areVersionCompatible(deployMuleVersion.get(), minMuleVersionValue); } } }  static void validate(Path projectBaseDir, Optional<String> deployMuleVersion); static void isMuleArtifactJsonPresent(Path projectBaseDir); static void isMuleArtifactJsonValid(Path projectBaseDir, Optional<String> deployMuleVersion);  }
@Test public void checkMinMuleVersionValueMissingTest() throws IOException, ValidationException { MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.empty()); assertThat("Missing fields should contain the minMuleVersion field name", missingFields, containsInAnyOrder("minMuleVersion")); }
@Test public void checkMinMuleVersionValueTest() throws IOException, ValidationException { MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.0.0 }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.empty()); assertThat("Missing fields should be empty", missingFields.isEmpty(), is(true)); }
@Test public void checkMinMuleVersionInvalidValueTest() throws IOException, ValidationException { expectedException.expect(ValidationException.class); expectedException.expectMessage("Version 4.0 does not comply with semantic versioning specification"); MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.0 }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.empty()); }
@Test public void checkMinMuleVersionAgainstDeploymentInvalidValueTest() throws IOException, ValidationException { expectedException.expect(ValidationException.class); MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.0.0 }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.of("3.8.0")); }
@Test public void checkMinMuleVersionAgainstDeploymentInvalidValue2Test() throws IOException, ValidationException { expectedException.expect(ValidationException.class); MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.1.0 }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.of("4.0.0")); }
@Test public void checkMinMuleVersionAgainstDeploymentInvalidValue3Test() throws IOException, ValidationException { expectedException.expect(ValidationException.class); MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.0.1 }"); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.of("4.0.0")); }
@Test public void checkMinMuleVersionAgainstDeploymentValidValueTest() throws IOException, ValidationException { MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.0.1 }"); when(deploymentConfigurationMock.getMuleVersion()).thenReturn(Optional.of("4.1.0")); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.empty()); }
@Test public void checkMinMuleVersionAgainstDeploymentValidValue2Test() throws IOException, ValidationException { MuleApplicationModel muleArtifact = new MuleApplicationModelJsonSerializer().deserialize("{ minMuleVersion:4.10.10 }"); when(deploymentConfigurationMock.getMuleVersion()).thenReturn(Optional.of("5.0.0")); checkMinMuleVersionValue(muleArtifact, missingFields, Optional.empty()); }