use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.
the class ExecServiceDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
try {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
} catch (InternalErrorException e) {
log.error(e.toString());
}
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setType(OwnerType.technical);
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
}
use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.
the class ExecServiceDenialDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setType(OwnerType.technical);
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
// Testing Destination #1
testDestinationId1 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId1, "test.destination." + testDestinationId1);
// Testing Destination #2
testDestinationId2 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId2, "test.destination." + testDestinationId2);
// Testing Facility #1
testFacilityId1 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId1, "Cluster_" + testFacilityId1);
// Testing Facility #2
testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
// Test ExecService #1 (Parent:testService1)
testExecService1 = new ExecService();
testExecService1.setDefaultDelay(1);
testExecService1.setDefaultRecurrence(1);
testExecService1.setEnabled(true);
testExecService1.setService(testService1);
testExecService1.setScript("/hellish/test/script");
testExecService1.setExecServiceType(ExecServiceType.GENERATE);
try {
testExecService1.setId(execServiceDao.insertExecService(testExecService1));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #2 (Parent:testService1)
testExecService2 = new ExecService();
testExecService2.setDefaultDelay(2);
testExecService2.setDefaultRecurrence(2);
testExecService2.setEnabled(true);
testExecService2.setService(testService2);
testExecService2.setScript("/hellish/test/script2");
testExecService2.setExecServiceType(ExecServiceType.SEND);
try {
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
}
use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.
the class ServicesManagerBlImplTest method setUp.
/*
* Tables with reference to service:
* - service_required_attrs
* - service_denials
* - resource_services
* - facility_service_destinations
* - service_service_packages
* - tasks
* - authz
*
*/
@Before
public void setUp() throws Exception {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
jdbcTemplate = new JdbcPerunTemplate(dataSource);
facility1 = new Facility();
facility2 = new Facility();
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setType(OwnerType.technical);
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
testService1.setDelay(1);
testService1.setRecurrence(1);
testService1.setEnabled(true);
testService1.setScript("/hellish/test/script");
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService2.setDelay(2);
testService2.setRecurrence(2);
testService2.setEnabled(true);
testService2.setScript("/hellish/test/script2");
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
// attribute
attribute = new AttributeDefinition();
attribute.setFriendlyName("ServicesManagerTestAttribute");
attribute.setDescription("TestingAttribute");
attribute.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
attribute.setType(String.class.getName());
attribute = ((PerunBl) perun).getAttributesManagerBl().createAttribute(perunSession, attribute);
// required attributes
List<AttributeDefinition> attrlist = new ArrayList<>();
attrlist.add(attribute);
((PerunBl) perun).getServicesManagerBl().addRequiredAttributes(perunSession, testService1, attrlist);
//
// Testing Destination #1
testDestinationId1 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId1, "test.destination." + testDestinationId1);
// Testing Destination #2
testDestinationId2 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId2, "test.destination." + testDestinationId2);
// Testing Facility #1
testFacilityId1 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId1, "Cluster_" + testFacilityId1);
facility1.setId(testFacilityId1);
// Testing Facility #2
testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
facility2.setId(testFacilityId2);
// vo
vo = new Vo(0, "ServicesManagerTestVo", "RMTestVo");
vo = ((PerunBl) perun).getVosManagerBl().createVo(perunSession, vo);
// resource
resource = new Resource();
resource.setName("ServicesManagerTestResource");
resource.setDescription("Testovaci");
resource = ((PerunBl) perun).getResourcesManagerBl().createResource(perunSession, resource, vo, facility1);
// resource services
((PerunBl) perun).getResourcesManagerBl().assignService(perunSession, resource, testService1);
// facility_service_destinations
destination = ((PerunBl) perun).getServicesManagerBl().getDestinationById(perunSession, testDestinationId1);
((PerunBl) perun).getServicesManagerBl().addDestination(perunSession, testService1, facility1, destination);
// service package
servicesPackage = new ServicesPackage();
servicesPackage.setName("ResourcesManagertTestSP");
servicesPackage.setDescription("testingServicePackage");
servicesPackage = ((PerunBl) perun).getServicesManagerBl().createServicesPackage(perunSession, servicesPackage);
// service_service_packages
((PerunBl) perun).getServicesManagerBl().addServiceToServicesPackage(perunSession, servicesPackage, testService1);
// tasks
task = new Task();
task.setFacility(facility1);
task.setService(testService1);
task.setSchedule(0L);
task.setStatus(TaskStatus.DONE);
List<Destination> destinationsList = new ArrayList<>();
destinationsList.add(destination);
task.setDestinations(destinationsList);
((PerunBl) perun).getTasksManagerBl().insertTask(perunSession, task);
// authz
// authz entries for service are removed in ServicesManagerImpl::deleteService(),
// no point in testing here
}
use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.
the class Auditer method setPerunPool.
public void setPerunPool(DataSource perunPool) {
this.jdbc = new JdbcPerunTemplate(perunPool);
this.jdbc.setQueryTimeout(BeansUtils.getCoreConfig().getQueryTimeout());
}
use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.
the class ExecServiceDependencyDaoTest method beforeClass.
@Before
public void beforeClass() {
try {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
} catch (InternalErrorException e) {
log.error(e.toString());
}
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = 0;
try {
newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setType(OwnerType.technical);
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
try {
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
} catch (InternalErrorException e) {
log.error(e.toString());
} catch (PrivilegeException e) {
log.error(e.toString());
} catch (ServiceExistsException e) {
log.error(e.toString());
}
// Test ExecService #1 (Parent:testService1)
testExecService1 = new ExecService();
testExecService1.setDefaultDelay(1);
testExecService1.setDefaultRecurrence(1);
testExecService1.setEnabled(true);
testExecService1.setService(testService1);
testExecService1.setScript("/hellish/test/script");
testExecService1.setExecServiceType(ExecServiceType.GENERATE);
try {
testExecService1.setId(execServiceDao.insertExecService(testExecService1));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #2 (Parent:testService1)
testExecService2 = new ExecService();
testExecService2.setDefaultDelay(2);
testExecService2.setDefaultRecurrence(2);
testExecService2.setEnabled(true);
testExecService2.setService(testService1);
testExecService2.setScript("/hellish/test/script2");
testExecService2.setExecServiceType(ExecServiceType.SEND);
try {
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #3 (Parent:testService2)
testExecService3 = new ExecService();
testExecService3.setDefaultDelay(3);
testExecService3.setDefaultRecurrence(3);
testExecService3.setEnabled(true);
testExecService3.setService(testService2);
testExecService3.setScript("/hellish/test/script3");
testExecService3.setExecServiceType(ExecServiceType.SEND);
try {
testExecService3.setId(execServiceDao.insertExecService(testExecService3));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
}
Aggregations