use of org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method getTaxonomyLevelComptences_byIdentity.
@Test
public void getTaxonomyLevelComptences_byIdentity() throws IOException, URISyntaxException {
// prepare a level, 1 user and 1 competence
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-7", "Taxonomy on rest", "Rest is cool", "Ext-tax-7");
TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-l-7", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
taxonomyService.addTaxonomyLevelCompetences(level, id, TaxonomyCompetenceTypes.teach, null);
dbInstance.commitAndCloseSession();
// get the competences
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(level.getKey().toString()).path("competences").path(id.getKey().toString()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent());
Assert.assertNotNull(competenceList);
Assert.assertEquals(1, competenceList.size());
TaxonomyCompetenceVO competence = competenceList.get(0);
Assert.assertEquals(id.getKey(), competence.getIdentityKey());
Assert.assertEquals(level.getKey(), competence.getTaxonomyLevelKey());
Assert.assertEquals(TaxonomyCompetenceTypes.teach.name(), competence.getTaxonomyCompetenceType());
}
use of org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method getTaxonomyComptencesByIdentity.
@Test
public void getTaxonomyComptencesByIdentity() throws IOException, URISyntaxException {
// prepare a level, 2 users and 2 competences
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-4");
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-20", "Taxonomy on rest", "Rest is cool", "Ext-tax-7");
TaxonomyLevel level1 = taxonomyService.createTaxonomyLevel("REST-Tax-l-21", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
TaxonomyLevel level2 = taxonomyService.createTaxonomyLevel("REST-Tax-l-22", "Level 1 on rest", "Level", "Ext-7", null, null, taxonomy);
taxonomyService.addTaxonomyLevelCompetences(level1, id, TaxonomyCompetenceTypes.teach, null);
taxonomyService.addTaxonomyLevelCompetences(level2, id, TaxonomyCompetenceTypes.have, null);
dbInstance.commitAndCloseSession();
// get the competences
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("competences").path(id.getKey().toString()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent());
Assert.assertNotNull(competenceList);
Assert.assertEquals(2, competenceList.size());
boolean foundComptenceId1 = false;
boolean foundComptenceId2 = false;
for (TaxonomyCompetenceVO competence : competenceList) {
if (competence.getTaxonomyLevelKey().equals(level1.getKey()) && competence.getIdentityKey().equals(id.getKey()) && TaxonomyCompetenceTypes.teach.name().equals(competence.getTaxonomyCompetenceType())) {
foundComptenceId1 = true;
} else if (competence.getTaxonomyLevelKey().equals(level2.getKey()) && competence.getIdentityKey().equals(id.getKey()) && TaxonomyCompetenceTypes.have.name().equals(competence.getTaxonomyCompetenceType())) {
foundComptenceId2 = true;
}
}
Assert.assertTrue(foundComptenceId1);
Assert.assertTrue(foundComptenceId2);
}
use of org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO 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.restapi.TaxonomyCompetenceVO in project OpenOLAT by OpenOLAT.
the class TaxonomyWebServiceTest method getTaxonomyLevelComptences.
@Test
public void getTaxonomyLevelComptences() throws IOException, URISyntaxException {
// prepare a level, 2 users and 2 competences
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("competence-2");
Taxonomy taxonomy = taxonomyService.createTaxonomy("REST-Tax-6", "Taxonomy on rest", "Rest is cool", "Ext-tax-6");
TaxonomyLevel level = taxonomyService.createTaxonomyLevel("REST-Tax-l-1", "Level 1 on rest", "Level", "Ext-3", null, null, taxonomy);
taxonomyService.addTaxonomyLevelCompetences(level, id1, TaxonomyCompetenceTypes.have, null);
taxonomyService.addTaxonomyLevelCompetences(level, id2, TaxonomyCompetenceTypes.manage, null);
dbInstance.commitAndCloseSession();
// get the competences
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("taxonomy").path(taxonomy.getKey().toString()).path("levels").path(level.getKey().toString()).path("competences").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<TaxonomyCompetenceVO> competenceList = parseTaxonomyComptencesArray(response.getEntity().getContent());
Assert.assertNotNull(competenceList);
Assert.assertEquals(2, competenceList.size());
boolean foundComptenceId1 = false;
boolean foundComptenceId2 = false;
for (TaxonomyCompetenceVO competence : competenceList) {
if (competence.getTaxonomyLevelKey().equals(level.getKey())) {
if (competence.getIdentityKey().equals(id1.getKey()) && TaxonomyCompetenceTypes.have.name().equals(competence.getTaxonomyCompetenceType())) {
foundComptenceId1 = true;
} else if (competence.getIdentityKey().equals(id2.getKey()) && TaxonomyCompetenceTypes.manage.name().equals(competence.getTaxonomyCompetenceType())) {
foundComptenceId2 = true;
}
}
}
Assert.assertTrue(foundComptenceId1);
Assert.assertTrue(foundComptenceId2);
}
use of org.olat.modules.taxonomy.restapi.TaxonomyCompetenceVO in project OpenOLAT by OpenOLAT.
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());
}
Aggregations