Search in sources :

Example 1 with ProvisionerInfo

use of co.cask.cdap.proto.profile.ProvisionerInfo in project cdap by caskdata.

the class ProfileStoreTest method testProfileStore.

@Test
public void testProfileStore() throws Exception {
    // get non-existing profile
    try {
        profileStore.getProfile(NamespaceId.DEFAULT.profile("nonExisting"));
        Assert.fail();
    } catch (NotFoundException e) {
    // expected
    }
    // delete non-existing profile
    try {
        profileStore.delete(NamespaceId.DEFAULT.profile("nonExisting"));
        Assert.fail();
    } catch (NotFoundException e) {
    // expected
    }
    ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
    Profile expected = new Profile("MyProfile", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
    // add a profile
    profileStore.add(profileId, expected);
    // get the profile
    Assert.assertEquals(expected, profileStore.getProfile(profileId));
    // add a profile which already exists
    try {
        profileStore.add(profileId, new Profile("MyProfile", "my another profile", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES)));
        Assert.fail();
    } catch (AlreadyExistsException e) {
    // expected
    }
    // add another profile to default namespace
    ProfileId profileId2 = NamespaceId.DEFAULT.profile("MyProfile2");
    Profile profile2 = new Profile("MyProfile2", "my 2nd profile for testing", new ProvisionerInfo("anotherProvisioner", PROPERTY_SUMMARIES));
    profileStore.add(profileId2, profile2);
    // get all profiles
    List<Profile> profiles = ImmutableList.of(expected, profile2);
    Assert.assertEquals(profiles, profileStore.getProfiles(NamespaceId.DEFAULT));
    // delete the second profile
    profileStore.delete(profileId2);
    Assert.assertEquals(ImmutableList.of(expected), profileStore.getProfiles(NamespaceId.DEFAULT));
    // add one and delete all profiles
    profileStore.add(profileId2, profile2);
    profileStore.deleteAll(NamespaceId.DEFAULT);
    Assert.assertEquals(Collections.EMPTY_LIST, profileStore.getProfiles(NamespaceId.DEFAULT));
}
Also used : ProfileId(co.cask.cdap.proto.id.ProfileId) AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) ProvisionerInfo(co.cask.cdap.proto.profile.ProvisionerInfo) NotFoundException(co.cask.cdap.common.NotFoundException) Profile(co.cask.cdap.proto.profile.Profile) Test(org.junit.Test)

Aggregations

AlreadyExistsException (co.cask.cdap.common.AlreadyExistsException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 ProfileId (co.cask.cdap.proto.id.ProfileId)1 Profile (co.cask.cdap.proto.profile.Profile)1 ProvisionerInfo (co.cask.cdap.proto.profile.ProvisionerInfo)1 Test (org.junit.Test)1