use of org.olat.modules.taxonomy.Taxonomy in project openolat by klemens.
the class TaxonomyWebServiceTest method putTaxonomyLevel_rootLevel.
@Test
public void putTaxonomyLevel_rootLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "PUT is cool", "PUT-tax-1");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
String uid = UUID.randomUUID().toString();
TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
levelVo.setIdentifier(uid);
levelVo.setDisplayName("PUT root level");
levelVo.setDescription("Try to PUT a root level");
levelVo.setExternalId("EXT-190");
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, levelVo);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// check the returned value
TaxonomyLevelVO newTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
Assert.assertNotNull(newTaxonomyLevelVo);
Assert.assertNotNull(newTaxonomyLevelVo.getKey());
Assert.assertEquals(uid, newTaxonomyLevelVo.getIdentifier());
Assert.assertEquals("PUT root level", newTaxonomyLevelVo.getDisplayName());
Assert.assertEquals("Try to PUT a root level", newTaxonomyLevelVo.getDescription());
Assert.assertEquals("EXT-190", newTaxonomyLevelVo.getExternalId());
// check the database
List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
Assert.assertNotNull(levels);
Assert.assertEquals(1, levels.size());
TaxonomyLevel savedLevel = levels.get(0);
Assert.assertEquals(newTaxonomyLevelVo.getKey(), savedLevel.getKey());
Assert.assertEquals(uid, savedLevel.getIdentifier());
Assert.assertEquals("PUT root level", savedLevel.getDisplayName());
Assert.assertEquals("Try to PUT a root level", savedLevel.getDescription());
Assert.assertEquals("EXT-190", savedLevel.getExternalId());
}
use of org.olat.modules.taxonomy.Taxonomy in project openolat by klemens.
the class TaxonomyWebServiceTest method getTaxonomyLevelTypeAllowedSubTypes.
@Test
public void getTaxonomyLevelTypeAllowedSubTypes() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-4", "Type 4 on rest", "Type", "EXT-Type-4", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-4-1", "Type 4.1 on rest", "Type", "EXT-Type-4-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-4-2", "Type 4.2 on rest", "Type", "EXT-Type-4-2", taxonomy);
dbInstance.commit();
List<TaxonomyLevelType> subTypes = new ArrayList<>(2);
subTypes.add(subType1);
subTypes.add(subType2);
type = taxonomyService.updateTaxonomyLevelType(type, subTypes);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").path(type.getKey().toString()).path("allowedSubTypes").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<TaxonomyLevelTypeVO> typeVoList = parseTaxonomyLevelTypesArray(response.getEntity().getContent());
Assert.assertNotNull(typeVoList);
Assert.assertEquals(2, typeVoList.size());
boolean found1 = false;
boolean found2 = false;
for (TaxonomyLevelTypeVO typeVo : typeVoList) {
if (subType1.getKey().equals(typeVo.getKey())) {
found1 = true;
} else if (subType2.getKey().equals(typeVo.getKey())) {
found2 = true;
}
}
Assert.assertTrue(found1);
Assert.assertTrue(found2);
}
use of org.olat.modules.taxonomy.Taxonomy in project openolat by klemens.
the class TaxonomyWebServiceTest method getTaxonomyLevelType.
@Test
public void getTaxonomyLevelType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-3", "Type 3 on rest", "Type", "EXT-Type-3", taxonomy);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").path(type.getKey().toString()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
TaxonomyLevelTypeVO typeVo = conn.parse(response, TaxonomyLevelTypeVO.class);
Assert.assertNotNull(typeVo);
}
use of org.olat.modules.taxonomy.Taxonomy in project openolat by klemens.
the class TaxonomyWebServiceTest method putTaxonomyLevelComptence.
@Test
public void putTaxonomyLevelComptence() throws IOException, URISyntaxException {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-8", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-r-8", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
TaxonomyCompetenceVO competenceVo = new TaxonomyCompetenceVO();
competenceVo.setIdentityKey(id.getKey());
competenceVo.setTaxonomyCompetenceType(TaxonomyCompetenceTypes.target.name());
competenceVo.setTaxonomyLevelKey(level.getKey());
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(level.getKey().toString()).path("competences").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, competenceVo);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// check the returned value
TaxonomyCompetenceVO newTaxonomyCompetenceVo = conn.parse(response, TaxonomyCompetenceVO.class);
Assert.assertNotNull(newTaxonomyCompetenceVo);
Assert.assertNotNull(newTaxonomyCompetenceVo.getKey());
Assert.assertEquals(id.getKey(), newTaxonomyCompetenceVo.getIdentityKey());
Assert.assertEquals(TaxonomyCompetenceTypes.target.name(), newTaxonomyCompetenceVo.getTaxonomyCompetenceType());
Assert.assertEquals(level.getKey(), newTaxonomyCompetenceVo.getTaxonomyLevelKey());
// check the database
List<TaxonomyCompetence> competences = taxonomyService.getTaxonomyCompetences(id, TaxonomyCompetenceTypes.target);
Assert.assertNotNull(competences);
Assert.assertEquals(1, competences.size());
TaxonomyCompetence competence = competences.get(0);
Assert.assertEquals(id, competence.getIdentity());
Assert.assertEquals(level, competence.getTaxonomyLevel());
Assert.assertEquals(TaxonomyCompetenceTypes.target, competence.getCompetenceType());
}
use of org.olat.modules.taxonomy.Taxonomy in project openolat by klemens.
the class TaxonomyWebServiceTest method getTaxonomy.
@Test
public void getTaxonomy() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-1", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
TaxonomyVO taxonomyVO = conn.parse(response, TaxonomyVO.class);
Assert.assertNotNull(taxonomyVO);
Assert.assertEquals(taxonomy.getKey(), taxonomyVO.getKey());
Assert.assertEquals("REST-Tax-1", taxonomyVO.getIdentifier());
Assert.assertEquals("Taxonomy on rest", taxonomyVO.getDisplayName());
Assert.assertEquals("Rest is cool", taxonomyVO.getDescription());
Assert.assertEquals("Ext-tax-1", taxonomyVO.getExternalId());
}
Aggregations