Search in sources :

Example 86 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class AttributesManagerBlImplUnitTests method setRequiredAttributes_services_f_r_u_m.

@Test
public void setRequiredAttributes_services_f_r_u_m() throws Exception {
    System.out.println(CLASS_NAME + "setRequiredAttributes_services_f_r_u_m");
    Service s1 = new Service(1, "s1");
    Service s2 = new Service(2, "s2");
    List<Service> services = Arrays.asList(s1, s2);
    Facility facility = new Facility(1, "f");
    Resource resource = new Resource(2, "r", "", facility.getId());
    User user = new User(3, "a", "b", "", "", "");
    Member member = new Member(4, user.getId());
    List<Attribute> attributes = new ArrayList<>();
    doCallRealMethod().when(attrManagerBlImplMock).setRequiredAttributes(any(), anyList(), any(), any(), any(), any(), anyBoolean());
    when(attrManagerBlImplMock.getRequiredAttributes(sessionMock, services, facility, resource, user, member)).thenReturn(attributes);
    attrManagerBlImplMock.setRequiredAttributes(sessionMock, services, facility, resource, user, member, true);
    verify(attrManagerBlImplMock, times(1)).setRequiredAttributes(eq(sessionMock), eq(facility), eq(resource), eq(user), eq(member), eq(attributes), eq(true));
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) Test(org.junit.Test)

Example 87 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class FacilitiesManagerBlImplTest method getAssignedUsersByServiceTest.

@Test
public void getAssignedUsersByServiceTest() throws Exception {
    System.out.println("FacilitiesManagerBlImpl.getAssignedUsers(facility, service)");
    Service service = new Service(0, "dummy_service");
    service = perun.getServicesManagerBl().createService(sess, service);
    perun.getResourcesManagerBl().assignService(sess, resource, service);
    List<User> users = perun.getFacilitiesManagerBl().getAssignedUsers(sess, facility, service);
    Assert.assertEquals(1, users.size());
    Assert.assertTrue(users.contains(user));
    users = perun.getFacilitiesManagerBl().getAssignedUsers(sess, facility2, service);
    Assert.assertTrue(users.isEmpty());
    // adding service3 to another facility should work
    perun.getResourcesManagerBl().assignService(sess, resource3, service);
    users = perun.getFacilitiesManagerBl().getAssignedUsers(sess, facility2, service);
    Assert.assertEquals(1, users.size());
    Assert.assertTrue(users.contains(user));
}
Also used : User(cz.metacentrum.perun.core.api.User) Service(cz.metacentrum.perun.core.api.Service) Test(org.junit.Test)

Example 88 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method getRequiredMemberResourceAttributesFromOneServiceWorkWithUserWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void getRequiredMemberResourceAttributesFromOneServiceWorkWithUserWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getRequiredMemberResourceAttributesFromOneServiceWorkWithUserWhenServiceNotExists");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    member = setUpMember();
    attributesManager.getRequiredAttributes(sess, new Service(), member, resource, true);
// shouldn't find service
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 89 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method getRequiredGroupResourceAttributesFromOneServiceWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void getRequiredGroupResourceAttributesFromOneServiceWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getRequiredGroupResourceAttributesFromOneServiceWhenServiceNotExists");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    group = setUpGroup();
    attributesManager.getRequiredAttributes(sess, new Service(), resource, group);
// shouldn't find service
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 90 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class ServicesManagerImpl method getServicesFromServicesPackage.

@Override
public List<Service> getServicesFromServicesPackage(PerunSession sess, ServicesPackage servicesPackage) {
    try {
        List<Service> services = new ArrayList<>();
        List<Integer> servicesId = jdbc.query("select service_id as id from service_service_packages where package_id=?", Utils.ID_MAPPER, servicesPackage.getId());
        for (Integer serviceId : servicesId) {
            try {
                services.add(getServiceById(sess, serviceId));
            } catch (ServiceNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
        }
        return services;
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)115 Test (org.junit.Test)64 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)55 Facility (cz.metacentrum.perun.core.api.Facility)31 ArrayList (java.util.ArrayList)26 Resource (cz.metacentrum.perun.core.api.Resource)22 Destination (cz.metacentrum.perun.core.api.Destination)20 Member (cz.metacentrum.perun.core.api.Member)17 User (cz.metacentrum.perun.core.api.User)17 Group (cz.metacentrum.perun.core.api.Group)15 Vo (cz.metacentrum.perun.core.api.Vo)13 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)13 Attribute (cz.metacentrum.perun.core.api.Attribute)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)11 Task (cz.metacentrum.perun.taskslib.model.Task)10 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)8 PerunClient (cz.metacentrum.perun.core.api.PerunClient)8 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)8 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)8