Search in sources :

Example 21 with CourseNodeVO

use of org.olat.restapi.support.vo.CourseNodeVO in project openolat by klemens.

the class CoursesContactElementTest method testFullConfig.

@Test
public void testFullConfig() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an contact node
    URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0").queryParam("shortTitle", "Contact-1").queryParam("longTitle", "Contact-long-1").queryParam("objectives", "Contact-objectives-1").queryParam("coaches", "true").queryParam("participants", "true").queryParam("groups", "").queryParam("areas", "").queryParam("to", "test@frentix.com;test2@frentix.com").queryParam("defaultSubject", "Hello by contact 1").queryParam("defaultBody", "Hello by contact 1 body").build();
    HttpPut method = conn.createPut(newContactUri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    // check the return values
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseNodeVO contactNode = conn.parse(response, CourseNodeVO.class);
    assertNotNull(contactNode);
    assertNotNull(contactNode.getId());
    // check the persisted value
    ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
    TreeNode node = course.getEditorTreeModel().getNodeById(contactNode.getId());
    assertNotNull(node);
    CourseEditorTreeNode editorCourseNode = (CourseEditorTreeNode) node;
    CourseNode courseNode = editorCourseNode.getCourseNode();
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    assertNotNull(config);
    assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOCOACHES), true);
    assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS), true);
    @SuppressWarnings("unchecked") List<String> tos = (List<String>) config.get(CONFIG_KEY_EMAILTOADRESSES);
    assertNotNull(tos);
    assertEquals(2, tos.size());
    assertEquals(config.get(CONFIG_KEY_MSUBJECT_DEFAULT), "Hello by contact 1");
    assertEquals(config.get(CONFIG_KEY_MBODY_DEFAULT), "Hello by contact 1 body");
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) List(java.util.List) CourseNode(org.olat.course.nodes.CourseNode) Test(org.junit.Test)

Example 22 with CourseNodeVO

use of org.olat.restapi.support.vo.CourseNodeVO in project openolat by klemens.

the class CoursesElementsTest method testCreateCoursePost.

@Test
public void testCreateCoursePost() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an empty course
    URI uri = getCoursesUri().queryParam("shortTitle", "course3").queryParam("title", "course3 long name").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseVO course = conn.parse(response, CourseVO.class);
    assertNotNull(course);
    assertNotNull(course.getKey());
    assertNotNull(course.getEditorRootNodeId());
    // create an structure node
    URI newStructureUri = getElementsUri(course).path("structure").build();
    HttpPost newStructureMethod = conn.createPost(newStructureUri, MediaType.APPLICATION_JSON);
    HttpEntity newStructureEnttiy = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "0").addTextBody("shortTitle", "Structure-0").addTextBody("longTitle", "Structure-long-0").addTextBody("objectives", "Structure-objectives-0").build();
    newStructureMethod.setEntity(newStructureEnttiy);
    HttpResponse newStructureResponse = conn.execute(newStructureMethod);
    int newStructureCode = newStructureResponse.getStatusLine().getStatusCode();
    assertTrue(newStructureCode == 200 || newStructureCode == 201);
    CourseNodeVO structureNode = conn.parse(newStructureResponse, CourseNodeVO.class);
    assertNotNull(structureNode);
    assertNotNull(structureNode.getId());
    assertEquals(structureNode.getShortTitle(), "Structure-0");
    assertEquals(structureNode.getLongTitle(), "Structure-long-0");
    assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0");
    assertEquals(structureNode.getParentId(), course.getEditorRootNodeId());
    // create single page
    URL pageUrl = CoursesElementsTest.class.getResource("singlepage.html");
    assertNotNull(pageUrl);
    File page = new File(pageUrl.toURI());
    URI newPageUri = getElementsUri(course).path("singlepage").build();
    HttpPost newPageMethod = conn.createPost(newPageUri, MediaType.APPLICATION_JSON);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", page, ContentType.APPLICATION_OCTET_STREAM, page.getName()).addTextBody("filename", page.getName()).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "1").addTextBody("shortTitle", "Single-Page-0").addTextBody("longTitle", "Single-Page-long-0").addTextBody("objectives", "Single-Page-objectives-0").build();
    newPageMethod.setEntity(entity);
    HttpResponse newPageCode = conn.execute(newPageMethod);
    assertTrue(newPageCode.getStatusLine().getStatusCode() == 200 || newPageCode.getStatusLine().getStatusCode() == 201);
    CourseNodeVO pageNode = conn.parse(newPageCode, CourseNodeVO.class);
    assertNotNull(pageNode);
    assertNotNull(pageNode.getId());
    assertEquals(pageNode.getShortTitle(), "Single-Page-0");
    assertEquals(pageNode.getLongTitle(), "Single-Page-long-0");
    assertEquals(pageNode.getLearningObjectives(), "Single-Page-objectives-0");
    assertEquals(structureNode.getParentId(), course.getEditorRootNodeId());
    // create a folder node
    URI newFolderUri = getElementsUri(course).path("folder").build();
    HttpPost newFolderMethod = conn.createPost(newFolderUri, MediaType.APPLICATION_JSON);
    String rule = "hasLanguage(\"de\")";
    conn.addEntity(newFolderMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "2"), new BasicNameValuePair("shortTitle", "Folder-0"), new BasicNameValuePair("longTitle", "Folder-long-0"), new BasicNameValuePair("objectives", "Folder-objectives-0"), new BasicNameValuePair("visibilityExpertRules", rule), new BasicNameValuePair("downloadExpertRules", rule), new BasicNameValuePair("uploadExpertRules", rule));
    HttpResponse newFolderCode = conn.execute(newFolderMethod);
    assertTrue(newFolderCode.getStatusLine().getStatusCode() == 200 || newFolderCode.getStatusLine().getStatusCode() == 201);
    CourseNodeVO folderNode = conn.parse(newFolderCode, CourseNodeVO.class);
    assertNotNull(folderNode);
    assertNotNull(folderNode.getId());
    assertEquals(folderNode.getShortTitle(), "Folder-0");
    assertEquals(folderNode.getLongTitle(), "Folder-long-0");
    assertEquals(folderNode.getLearningObjectives(), "Folder-objectives-0");
    assertEquals(folderNode.getParentId(), course.getEditorRootNodeId());
    // create a forum node
    URI newForumUri = getElementsUri(course).path("forum").build();
    HttpPost newForumMethod = conn.createPost(newForumUri, MediaType.APPLICATION_JSON);
    conn.addEntity(newForumMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "3"), new BasicNameValuePair("shortTitle", "Forum-0"), new BasicNameValuePair("longTitle", "Forum-long-0"), new BasicNameValuePair("objectives", "Forum-objectives-0"));
    HttpResponse newForumCode = conn.execute(newForumMethod);
    assertTrue(newForumCode.getStatusLine().getStatusCode() == 200 || newForumCode.getStatusLine().getStatusCode() == 201);
    CourseNodeVO forumNode = conn.parse(newForumCode, CourseNodeVO.class);
    assertNotNull(forumNode);
    assertNotNull(forumNode.getId());
    assertEquals(forumNode.getShortTitle(), "Forum-0");
    assertEquals(forumNode.getLongTitle(), "Forum-long-0");
    assertEquals(forumNode.getLearningObjectives(), "Forum-objectives-0");
    assertEquals(forumNode.getParentId(), course.getEditorRootNodeId());
    // create a task node
    URI newTaskUri = getElementsUri(course).path("task").build();
    HttpPost newTaskMethod = conn.createPost(newTaskUri, MediaType.APPLICATION_JSON);
    conn.addEntity(newTaskMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "4"), new BasicNameValuePair("shortTitle", "Task-0"), new BasicNameValuePair("longTitle", "Task-long-0"), new BasicNameValuePair("objectives", "Task-objectives-0"), new BasicNameValuePair("points", "25"), new BasicNameValuePair("text", "A very difficult test"));
    HttpResponse newTaskCode = conn.execute(newTaskMethod);
    assertTrue(newTaskCode.getStatusLine().getStatusCode() == 200 || newTaskCode.getStatusLine().getStatusCode() == 201);
    CourseNodeVO taskNode = conn.parse(newTaskCode, CourseNodeVO.class);
    assertNotNull(taskNode);
    assertNotNull(taskNode.getId());
    assertEquals(taskNode.getShortTitle(), "Task-0");
    assertEquals(taskNode.getLongTitle(), "Task-long-0");
    assertEquals(taskNode.getLearningObjectives(), "Task-objectives-0");
    assertEquals(taskNode.getParentId(), course.getEditorRootNodeId());
    // create a test node
    URI newTestUri = getElementsUri(course).path("test").build();
    HttpPost newTestMethod = conn.createPost(newTestUri, MediaType.APPLICATION_JSON);
    conn.addEntity(newTestMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("testResourceableId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "5"), new BasicNameValuePair("shortTitle", "Test-0"), new BasicNameValuePair("longTitle", "Test-long-0"), new BasicNameValuePair("objectives", "Test-objectives-0"));
    HttpResponse newTestCode = conn.execute(newTestMethod);
    // must bind a real test
    assertTrue(newTestCode.getStatusLine().getStatusCode() == 404);
    EntityUtils.consume(newTestCode.getEntity());
    /*
		assertTrue(newTestCode == 200 || newTestCode == 201);
		String newTestBody = newTestMethod.getResponseBodyAsString();
		CourseNodeVO testNode = parse(newTestBody, CourseNodeVO.class);
		assertNotNull(testNode);
		assertNotNull(testNode.getId());
		assertEquals(testNode.getShortTitle(), "Test-0");
		assertEquals(testNode.getParentId(), course.getEditorRootNodeId());
		*/
    // create an assessment node
    URI newAssessmentUri = getElementsUri(course).path("assessment").build();
    HttpPost newAssessmentMethod = conn.createPost(newAssessmentUri, MediaType.APPLICATION_JSON);
    conn.addEntity(newAssessmentMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "5"), new BasicNameValuePair("shortTitle", "Assessment-0"), new BasicNameValuePair("longTitle", "Assessment-long-0"), new BasicNameValuePair("objectives", "Assessment-objectives-0"));
    HttpResponse newAssessmentCode = conn.execute(newAssessmentMethod);
    assertTrue(newAssessmentCode.getStatusLine().getStatusCode() == 200 || newAssessmentCode.getStatusLine().getStatusCode() == 201);
    CourseNodeVO assessmentNode = conn.parse(newAssessmentCode, CourseNodeVO.class);
    assertNotNull(assessmentNode);
    assertNotNull(assessmentNode.getId());
    assertEquals(assessmentNode.getShortTitle(), "Assessment-0");
    assertEquals(assessmentNode.getLongTitle(), "Assessment-long-0");
    assertEquals(assessmentNode.getLearningObjectives(), "Assessment-objectives-0");
    assertEquals(assessmentNode.getParentId(), course.getEditorRootNodeId());
    // create an contact node
    URI newContactUri = getElementsUri(course).path("contact").build();
    HttpPost newContactMethod = conn.createPost(newContactUri, MediaType.APPLICATION_JSON);
    conn.addEntity(newContactMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "6"), new BasicNameValuePair("shortTitle", "Contact-0"), new BasicNameValuePair("longTitle", "Contact-long-0"), new BasicNameValuePair("objectives", "Contact-objectives-0"));
    HttpResponse newContactCode = conn.execute(newContactMethod);
    assertEquals(200, newContactCode.getStatusLine().getStatusCode());
    CourseNodeVO contactNode = conn.parse(newContactCode, CourseNodeVO.class);
    assertNotNull(contactNode);
    assertNotNull(contactNode.getId());
    assertEquals(contactNode.getShortTitle(), "Contact-0");
    assertEquals(contactNode.getLongTitle(), "Contact-long-0");
    assertEquals(contactNode.getLearningObjectives(), "Contact-objectives-0");
    assertEquals(contactNode.getParentId(), course.getEditorRootNodeId());
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) URL(java.net.URL) Test(org.junit.Test)

Aggregations

CourseNodeVO (org.olat.restapi.support.vo.CourseNodeVO)22 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)12 HttpResponse (org.apache.http.HttpResponse)12 HttpPut (org.apache.http.client.methods.HttpPut)12 Test (org.junit.Test)12 CourseNode (org.olat.course.nodes.CourseNode)12 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)12 HttpEntity (org.apache.http.HttpEntity)8 CourseVO (org.olat.restapi.support.vo.CourseVO)8 File (java.io.File)6 URL (java.net.URL)6 HttpPost (org.apache.http.client.methods.HttpPost)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)6 ModuleConfiguration (org.olat.modules.ModuleConfiguration)6 Condition (org.olat.course.condition.Condition)4 IQSURVCourseNode (org.olat.course.nodes.IQSURVCourseNode)4 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)4 MSCourseNode (org.olat.course.nodes.MSCourseNode)4