import static org.junit.Assert.*; import java.io.IOException; import java.util.ArrayList; import java.util.UUID; import org.junit.Before; import org.junit.Test; import org.mortbay.jetty.HttpStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import dao.entities.DMPDao; import dao.entities.DMPProfileDao; import dao.entities.DataRepositoryDao; import dao.entities.DatasetDao; import dao.entities.DatasetProfileDao; import dao.entities.DatasetProfileRulesetDao; import dao.entities.DatasetProfileViewstyleDao; import dao.entities.OrganisationDao; import dao.entities.ProjectDao; import dao.entities.RegistryDao; import dao.entities.ResearcherDao; import dao.entities.ServiceDao; import dao.entities.UserInfoDao; import entities.DatasetProfile; import entities.DatasetProfileRuleset; import entities.DatasetProfileViewstyle; import entities.Service; import helpers.SerializerProvider; import rest.entities.DMPs; import rest.entities.DatasetProfiles; import rest.entities.Datasets; import rest.entities.Projects; import rest.entities.Services; @ComponentScan(basePackages = "dao, entities, controller, login, proxy, rest") public class TestRest { @Autowired private DataRepositoryDao dataRepositoryDao; @Autowired private DatasetDao datasetDao; @Autowired private DatasetProfileDao datasetProfileDao; @Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao; @Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao; @Autowired private DMPDao dMPDao; @Autowired private DMPProfileDao dMPProfileDao; @Autowired private OrganisationDao organisationDao; @Autowired private ProjectDao projectDao; @Autowired private RegistryDao registryDao; @Autowired private ResearcherDao researcherDao; @Autowired private ServiceDao serviceDao; @Autowired private UserInfoDao userInfoDao; Gson gson = new Gson(); private static String userID = "0f51f686-a2ce-47c1-9433-00736787aa88"; private ApplicationContext context; private Projects projectsService; private Datasets datasetsService; private DatasetProfiles datasetProfilesService; private DMPs dmpsService; private Services servicesService; @Before public void setupAll() { Authentication dummy = new UsernamePasswordAuthenticationToken(userID, "test-creds", new ArrayList<>()); SecurityContextHolder.getContext().setAuthentication(dummy); context = new ClassPathXmlApplicationContext("applicationContextTEST.xml"); projectsService = context.getBean(Projects.class); datasetsService = context.getBean(Datasets.class); datasetProfilesService = context.getBean(DatasetProfiles.class); dmpsService = context.getBean(DMPs.class); servicesService = context.getBean(Services.class); } // @Test public void testDatasetProfile() { // DatasetProfile datasetProfile = new DatasetProfile(); // datasetProfile.setLabel("Sample-Dataset-Profile"); // datasetProfile.setDefinition("Sample-Dataset-Profile definition"); // // DatasetProfileRuleset dpr = new DatasetProfileRuleset(); // dpr.setLabel("Sample-Dataset-Profile ruleset"); // dpr.setDefinition("dpr definition"); // datasetProfile.setRuleset(dpr); // // DatasetProfileViewstyle dpv = new DatasetProfileViewstyle(); // dpv.setLabel("Sample-Dataset-Profile viewstyle"); // dpv.setDefinition("dpv definition"); // datasetProfile.setViewstyle(dpv); // // datasetProfilesService.createDatasetProfile(datasetProfile); // // assertNotNull(datasetProfile.getId()); } // @Test public void testDatasetProfile2() { // DatasetProfile datasetProfile = new DatasetProfile(); // datasetProfile.setLabel("Sample-Dataset-Profile-222"); // datasetProfile.setDefinition("Sample-Dataset-Profile-222 definition"); // // DatasetProfileRuleset dpr = new DatasetProfileRuleset(); // dpr.setLabel("Sample-Dataset-Profile-222 ruleset"); // dpr.setDefinition("dpr definition"); // datasetProfile.setRuleset(dpr); // // DatasetProfileViewstyle dpv = new DatasetProfileViewstyle(); // dpv.setLabel("Sample-Dataset-Profile-222 viewstyle"); // dpv.setDefinition("dpv definition"); // datasetProfile.setViewstyle(dpv); // // ResponseEntity createResp = datasetProfilesService.createDatasetProfile(datasetProfile); // assertEquals(201, createResp.getStatusCodeValue()); // // datasetProfile.setLabel("SAMPLE-DATASET-PROFILE-222"); // dpr.setLabel("SAMPLE-DATASET-PROFILE-222"); // dpv.setLabel("SAMPLE-DATASET-PROFILE-222"); // // ResponseEntity updResp = datasetProfilesService.updateDatasetProfile(datasetProfile); // assertEquals(201, updResp.getStatusCodeValue()); // // ResponseEntity delResp = datasetProfilesService.deleteDatasetProfile(datasetProfile); // assertEquals(200, delResp.getStatusCodeValue()); } // @Test public void testServiceService() { Service service = new Service(); service.setId(UUID.fromString("37acad15-39a1-46f3-a6f3-1bf0eaefaadc")); ResponseEntity delResp = servicesService.delete(service); assertEquals(201, delResp.getStatusCodeValue()); } // @Test public void testProject() { System.out.println(projectsService.listProjects().getBody()); System.out.println(dmpsService.listDMPs().getBody()); assertEquals("aaa", "aaa"); } }