Search in sources :

Example 1 with TaxonomyLevelTypeVO

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

Example 2 with TaxonomyLevelTypeVO

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

Example 3 with TaxonomyLevelTypeVO

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

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

Example 4 with TaxonomyLevelTypeVO

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

Example 5 with TaxonomyLevelTypeVO

use of org.olat.modules.taxonomy.restapi.TaxonomyLevelTypeVO 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);
}
Also used : TaxonomyLevelTypeVO(org.olat.modules.taxonomy.restapi.TaxonomyLevelTypeVO) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) 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 TaxonomyLevelTypeVO (org.olat.modules.taxonomy.restapi.TaxonomyLevelTypeVO)8 HttpGet (org.apache.http.client.methods.HttpGet)6 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)6 ArrayList (java.util.ArrayList)2 HttpPut (org.apache.http.client.methods.HttpPut)2