Search in sources :

Example 1 with TaxonomyLevelVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelVO 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());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 2 with TaxonomyLevelVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelVO 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());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 3 with TaxonomyLevelVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelVO in project OpenOLAT by OpenOLAT.

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());
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 4 with TaxonomyLevelVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelVO in project OpenOLAT by OpenOLAT.

the class TaxonomyWebServiceTest method putTaxonomyLevel_subLevel.

@Test
public void putTaxonomyLevel_subLevel() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-3", "Taxonomy on rest", "PUT is cool, yes!", "PUT-tax-2");
    TaxonomyLevel rootLevel = taxonomyService.createTaxonomyLevel("REST-Tax-r-1", "Root level on rest", "Level", "Ext-23", null, null, taxonomy);
    TaxonomyLevelType type = taxonomyService.createTaxonomyLevelType("Sub-type", "Type for a sub level", "All is in the title", "TYP-23", taxonomy);
    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 a sub level");
    levelVo.setDescription("Try to PUT a level above the root");
    levelVo.setExternalId("EXT-191");
    levelVo.setParentKey(rootLevel.getKey());
    levelVo.setTypeKey(type.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 returned value
    TaxonomyLevelVO newTaxonomyLevelVo = conn.parse(response, TaxonomyLevelVO.class);
    Assert.assertNotNull(newTaxonomyLevelVo);
    Assert.assertNotNull(newTaxonomyLevelVo.getKey());
    Assert.assertEquals(uid, newTaxonomyLevelVo.getIdentifier());
    Assert.assertEquals("PUT a sub level", newTaxonomyLevelVo.getDisplayName());
    Assert.assertEquals("EXT-191", newTaxonomyLevelVo.getExternalId());
    Assert.assertEquals(rootLevel.getKey(), newTaxonomyLevelVo.getParentKey());
    Assert.assertEquals(type.getKey(), newTaxonomyLevelVo.getTypeKey());
    // check the database
    TaxonomyLevel savedLevel = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(newTaxonomyLevelVo.getKey()));
    Assert.assertNotNull(savedLevel);
    Assert.assertEquals(newTaxonomyLevelVo.getKey(), savedLevel.getKey());
    Assert.assertEquals(newTaxonomyLevelVo.getParentKey(), savedLevel.getParent().getKey());
    // check parent line
    List<TaxonomyLevel> parentLine = taxonomyService.getTaxonomyLevelParentLine(savedLevel, taxonomy);
    Assert.assertNotNull(parentLine);
    Assert.assertEquals(2, parentLine.size());
    Assert.assertEquals(rootLevel, parentLine.get(0));
    Assert.assertEquals(savedLevel, parentLine.get(1));
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) HttpResponse(org.apache.http.HttpResponse) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 5 with TaxonomyLevelVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelVO in project OpenOLAT by OpenOLAT.

the class TaxonomyWebServiceTest method getFlatTaxonomyLevels.

@Test
public void getFlatTaxonomyLevels() throws IOException, URISyntaxException {
    Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-2", "Taxonomy on rest", "Rest is cool", "Ext-tax-1");
    TaxonomyLevel level1 = taxonomyService.createTaxonomyLevel("REST-Tax-l-1", "Level 1 on rest", "Level", "Ext-3", null, null, taxonomy);
    TaxonomyLevel level2 = taxonomyService.createTaxonomyLevel("REST-Tax-l-2", "Level 2 on rest", "Level", "Ext-4", null, null, 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").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<TaxonomyLevelVO> taxonomyLevelVOList = parseTaxonomyLevelsArray(response.getEntity().getContent());
    Assert.assertNotNull(taxonomyLevelVOList);
    Assert.assertEquals(2, taxonomyLevelVOList.size());
    boolean found1 = false;
    boolean found2 = false;
    for (TaxonomyLevelVO levelVo : taxonomyLevelVOList) {
        if (level1.getKey().equals(levelVo.getKey())) {
            found1 = true;
        } else if (level2.getKey().equals(levelVo.getKey())) {
            found2 = true;
        }
    }
    Assert.assertTrue(found1);
    Assert.assertTrue(found2);
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelVO) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)8 HttpResponse (org.apache.http.HttpResponse)8 Test (org.junit.Test)8 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 TaxonomyLevelVO (org.olat.modules.taxonomy.restapi.TaxonomyLevelVO)8 HttpPut (org.apache.http.client.methods.HttpPut)6 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)4 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)4 HttpGet (org.apache.http.client.methods.HttpGet)2