### Question:
ProfileService { public void saveProfile(ProfileId profileId, Profile profile) throws MethodNotAllowedException { TransactionRunners.run(transactionRunner, context -> { if (!cConf.getBoolean(Constants.Profile.UPDATE_ALLOWED)) { throw new MethodNotAllowedException("Compute profile creation and update are not allowed"); } ProfileStore dataset = ProfileStore.get(context); if (profileId.equals(ProfileId.NATIVE)) { try { dataset.getProfile(profileId); throw new MethodNotAllowedException(String.format("Profile Native %s already exists. It cannot be updated", profileId.getScopedName())); } catch (NotFoundException e) { } } dataset.saveProfile(profileId, profile); }, MethodNotAllowedException.class); } @Inject  ProfileService(CConfiguration cConf,
                        MetricsSystemClient metricsSystemClient,
                        TransactionRunner transactionRunner); Profile getProfile(ProfileId profileId); Profile getProfile(ProfileId profileId, Map<String, String> overrides); List<Profile> getProfiles(NamespaceId namespaceId, boolean includeSystem); void saveProfile(ProfileId profileId, Profile profile); void createIfNotExists(ProfileId profileId, Profile profile); void deleteProfile(ProfileId profileId); void deleteAllProfiles(NamespaceId namespaceId); @VisibleForTesting void clear(); void enableProfile(ProfileId profileId); void disableProfile(ProfileId profileId); Set<EntityId> getProfileAssignments(ProfileId profileId); void addProfileAssignment(ProfileId profileId,
                                   EntityId entityId); void removeProfileAssignment(ProfileId profileId, EntityId entityId);  }### Answer:
@Test(expected = MethodNotAllowedException.class) public void testProfileCreationDisabled() throws Exception { CConfiguration cConfWithProfileCreationDisabled = CConfiguration.copy(cConf); cConfWithProfileCreationDisabled.setBoolean(Constants.Profile.UPDATE_ALLOWED, false); ProfileService service = new ProfileService(cConfWithProfileCreationDisabled, getInjector().getInstance(MetricsSystemClient.class), getInjector().getInstance(TransactionRunner.class)); ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile"); Profile profile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES)); service.saveProfile(profileId, profile); }
@Test(expected = MethodNotAllowedException.class) public void testProfileUpdateDisallowed() throws Exception { ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile"); Profile profile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES)); profileService.saveProfile(profileId, profile); CConfiguration cConfWithProfileCreationDisabled = CConfiguration.copy(cConf); cConfWithProfileCreationDisabled.setBoolean(Constants.Profile.UPDATE_ALLOWED, false); ProfileService service = new ProfileService(cConfWithProfileCreationDisabled, getInjector().getInstance(MetricsSystemClient.class), getInjector().getInstance(TransactionRunner.class)); Profile newProfile = new Profile("MyProfile", "label", "my new profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES)); service.saveProfile(profileId, newProfile); }