use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class TaxonomyWebServiceTest method putTaxonomyLevelType.
@Test
public void putTaxonomyLevelType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
TaxonomyLevelTypeVO newTypeVo = new TaxonomyLevelTypeVO();
String identifier = UUID.randomUUID().toString();
newTypeVo.setIdentifier(identifier);
newTypeVo.setDisplayName("REST-Type-5");
newTypeVo.setDescription("Unused description");
newTypeVo.setExternalId("EXT-type-5");
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("types").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, newTypeVo);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
TaxonomyLevelTypeVO typeVo = conn.parse(response, TaxonomyLevelTypeVO.class);
Assert.assertNotNull(typeVo);
Assert.assertEquals(identifier, typeVo.getIdentifier());
Assert.assertEquals("REST-Type-5", typeVo.getDisplayName());
Assert.assertEquals("Unused description", typeVo.getDescription());
Assert.assertEquals("EXT-type-5", typeVo.getExternalId());
}
use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method deleteTaxonomyLevel.
@Test
public void deleteTaxonomyLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Del-1", "Taxonomy on rest", "Delete is sad!", "DELETE-tax-1");
TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Del-root", "Root level on rest", "Level", "Ext-55", null, null, taxonomy);
TaxonomyLevel levelToDelete = taxonomyService.createTaxonomyLevel("REST-Del-u-1", "Sub level on rest", "Level", "Ext-56", null, rootLevel, 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("levels").path(levelToDelete.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check the deleted value
TaxonomyLevel deletedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelToDelete.getKey()));
Assert.assertNull(deletedLevel);
TaxonomyLevel survivingRootLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(rootLevel.getKey()));
Assert.assertNotNull(survivingRootLevel);
}
use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method updateTaxonomyLevel.
/**
* Update level.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void updateTaxonomyLevel() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-4", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Root level on rest", "Level", "Ext-25", null, null, taxonomy);
TaxonomyLevel levelToUpdate = taxonomyService.createTaxonomyLevel("REST-Tax-u-1", "Sub level on rest", "Level", "Ext-26", null, rootLevel, taxonomy);
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-27", taxonomy);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(taxonomy);
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
TaxonomyLevelVO levelVo = new TaxonomyLevelVO();
levelVo.setKey(levelToUpdate.getKey());
levelVo.setIdentifier("Updated id");
levelVo.setDisplayName("Updated name");
levelVo.setDescription("Updated description");
levelVo.setExternalId("Updated ext.");
levelVo.setTypeKey(type.getKey());
levelVo.setParentKey(rootLevel.getKey());
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 updated value
TaxonomyLevelVO updatedTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
Assert.assertNotNull(updatedTaxonomyLevelVo);
Assert.assertEquals("Updated id", updatedTaxonomyLevelVo.getIdentifier());
Assert.assertEquals("Updated name", updatedTaxonomyLevelVo.getDisplayName());
Assert.assertEquals("Updated description", updatedTaxonomyLevelVo.getDescription());
Assert.assertEquals("Updated ext.", updatedTaxonomyLevelVo.getExternalId());
Assert.assertEquals(rootLevel.getKey(), updatedTaxonomyLevelVo.getParentKey());
Assert.assertEquals(type.getKey(), updatedTaxonomyLevelVo.getTypeKey());
// check the database
TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(updatedTaxonomyLevelVo.getKey()));
Assert.assertNotNull(savedLevel);
Assert.assertEquals("Updated id", savedLevel.getIdentifier());
Assert.assertEquals("Updated name", savedLevel.getDisplayName());
Assert.assertEquals("Updated description", savedLevel.getDescription());
Assert.assertEquals("Updated ext.", savedLevel.getExternalId());
Assert.assertEquals(rootLevel.getKey(), savedLevel.getParent().getKey());
Assert.assertEquals(type.getKey(), savedLevel.getType().getKey());
}
use of org.olat.modules.taxonomy.Taxonomy in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method disallowTaxonomyLevelTypeAllowedSubType.
@Test
public void disallowTaxonomyLevelTypeAllowedSubType() throws IOException, URISyntaxException {
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-6", "Taxonomy on rest", "Rest is cool", "Ext-tax-6");
TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("REST-Type-6", "Type 6 on rest", "Type", "EXT-Type-6", taxonomy);
TaxonomyLevelType subType1 = taxonomyService.createTaxonomyLevelType("REST-Type-6-1", "Type 6.1 on rest", "Type", "EXT-Type-6-1", taxonomy);
TaxonomyLevelType subType2 = taxonomyService.createTaxonomyLevelType("REST-Type-6-2", "Type 6.2 on rest", "Type", "EXT-Type-6-2", taxonomy);
TaxonomyLevelType subType3 = taxonomyService.createTaxonomyLevelType("REST-Type-6-3", "Type 6.3 on rest", "Type", "EXT-Type-6-3", taxonomy);
dbInstance.commit();
List<TaxonomyLevelType> allowedSubTypes = new ArrayList<>();
allowedSubTypes.add(subType1);
allowedSubTypes.add(subType2);
allowedSubTypes.add(subType3);
type = taxonomyService.updateTaxonomyLevelType(type, allowedSubTypes);
dbInstance.commitAndCloseSession();
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").path(subType2.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
TaxonomyLevelType reloadedType = taxonomyService.getTaxonomyLevelType(type);
Set<TaxonomyLevelTypeToType> typeToTypes = reloadedType.getAllowedTaxonomyLevelSubTypes();
Assert.assertEquals(2, typeToTypes.size());
boolean found1 = false;
boolean found2 = false;
boolean found3 = false;
for (TaxonomyLevelTypeToType typeToType : typeToTypes) {
TaxonomyLevelType subType = typeToType.getAllowedSubTaxonomyLevelType();
if (subType1.getKey().equals(subType.getKey())) {
found1 = true;
} else if (subType2.getKey().equals(subType.getKey())) {
found2 = true;
} else if (subType3.getKey().equals(subType.getKey())) {
found3 = true;
}
}
Assert.assertTrue(found1);
Assert.assertFalse(found2);
Assert.assertTrue(found3);
}
Aggregations