@Test public void testMissingProfileName() throws Exception { List<ProvisionerPropertyValue> properties = new ArrayList<>(); properties.add(new ProvisionerPropertyValue("name1", "val1", true)); properties.add(new ProvisionerPropertyValue("name2", "val2", true)); ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties); SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("", "label", "desc", provisionerInfo); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@Test public void testMissingProvisionerInfo() throws Exception { SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("name", "label", "desc", null); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@Test public void testExistingIsUnmodified() throws Exception { // write a profile ProfileId profileId = NamespaceId.SYSTEM.profile("p1"); List<ProvisionerPropertyValue> properties = new ArrayList<>(); properties.add(new ProvisionerPropertyValue("name1", "val1", true)); properties.add(new ProvisionerPropertyValue("name2", "val2", true)); ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties); Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo); profileService.saveProfile(profileId, profile); // run the bootstrap step and make sure it succeeded SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), "different label", "different desciption", profile.getProvisioner()); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED); Assert.assertEquals(expected, result); // check that it didn't overwrite the existing profile Assert.assertEquals(profile, profileService.getProfile(profileId)); } }
@Test public void testCreation() throws Exception { ProfileId profileId = NamespaceId.SYSTEM.profile("p1"); try { profileService.getProfile(profileId); Assert.fail("profile should not exist."); } catch (NotFoundException e) { // expected } List<ProvisionerPropertyValue> properties = new ArrayList<>(); properties.add(new ProvisionerPropertyValue("name1", "val1", true)); properties.add(new ProvisionerPropertyValue("name2", "val2", true)); ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties); Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo); SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getProvisioner()); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED); Assert.assertEquals(expected, result); Assert.assertEquals(profile, profileService.getProfile(profileId)); }