How can I create testplan from oslc4j using templates in QM?
Using oslc(QM) I did not find example which includes creation of testplan. Could you please provide example using testplan templates?
Test case example with oslc?
One answer
I think, I solved templated issue but I have some problem at required fields.
// get the URL of the OSLC ChangeManagement service from the rootservices document String catalogUrl = client.getCatalogUrl(rqmProperties.getWebContextUrl(), OSLCConstants.OSLC_QM_V2);
// find the OSLC Service Provider for the project area we want to work with URI uri = URI.create(testPlanRequest.getProjectAreaName().replaceAll(" ", "%20")); String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, uri.getPath());
String projectId = serviceProviderUrl.substring(0, serviceProviderUrl.lastIndexOf("/")); projectId = projectId.substring(projectId.lastIndexOf("/") + 1);
//Get the Creation Factory URL for test cases so that we can create a test case String oslcTestPlanType = (new TestPlan()).getRdfTypes()[0].toString(); String testPlanFactory = client.lookupCreationFactory(serviceProviderUrl, OSLCConstants.OSLC_QM_V2, oslcTestPlanType);
// We need to use Resource shapes to properly handle date attributes attributes, // so they aren't interpreted as dateTime. // The following 4 lines will enable the logic to properly handle date attributes List<ResourceShape> shapes = new ArrayList<ResourceShape>(); //shapes.add(featureInstanceShape); OSLC4JUtils.setShapes(shapes); OSLC4JUtils.setInferTypeFromShape("true");
TestPlan testPlan = null; if((testPlanFactory == null )){
throw new Exception("testPlanFactory can not be null"); } else {
// initialize test plan
testPlan = new TestPlan();
testPlan.setTitle(testPlanRequest.getTitle());
// set teamArea
QName teamAreaQName = new QName("http://jazz.net/ns/process#", "teamArea", "process");
URI teamAreaUri = new URI("https://...:.../qm/process/team-areas/_qsWPYSCYEeWbKqGgOKE7Vw");
testPlan.getExtendedProperties().put(teamAreaQName, teamAreaUri);
// set template
QName templateQName = new QName("http://jazz.net/ns/qm/rqm#", "template", "rqm_qm");
URI templateUri = new URI("https://...:.../qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Test+ve+Kalite+Y%C3%B6netimi+%28RQMDev%29/template/testplan/com.ibm.rqm.planning.templates.testplan.template_1435832514936");
testPlan.getExtendedProperties().put(teamAreaQName, templateUri);
// create the test plan
Response creationResponse = client.createResource(testPlanFactory, testPlan, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML);
if(creationResponse.getStatus() != 201)
throw new Exception("Error :" + creationResponse.getStatusInfo());
String reqUrl = creationResponse.getStringHeaders().getFirst(HttpHeaders.LOCATION);
creationResponse.readEntity(String.class);
// check that everything was properly created
if (reqUrl == null) {
throw new Exception("Failed to create an artifact");
}else {
return testPlan;
} }