### Question:
SystemProfileCreator extends BaseStepExecutor<SystemProfileCreator.Arguments> { @Override public void execute(Arguments arguments) { Profile profile = new Profile(arguments.name, arguments.getLabel(), arguments.getDescription(), EntityScope.SYSTEM, arguments.getProvisioner()); profileService.createIfNotExists(arguments.getId(), profile); } @Inject  SystemProfileCreator(ProfileService profileService); @Override void execute(Arguments arguments);  }### Answer:
@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 testInvalidArgumentStructure() throws Exception { JsonObject arguments = new JsonObject(); arguments.addProperty("name", "p1"); arguments.addProperty("description", "desc"); arguments.addProperty("label", "some label"); arguments.addProperty("provisioner", "native"); BootstrapStepResult result = profileCreator.execute("label", arguments); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@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) { } 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)); }
@Test public void testExistingIsUnmodified() throws Exception { 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); 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); Assert.assertEquals(profile, profileService.getProfile(profileId)); }