owl ontology (data properties) - semantic-web

In Protégé, I've created an ontology with classes Service, Attributes, etc., and an object property hasAttributes as follow:
Service has Attributes Attributes (serviceIdentifier:String, Type(String), Description (sting), providerIdentifier (String), InputParameter ( ), OutputParameter (), price (Integer)
My question is: must we consider serviceidentifier, type, description, etc., as subclasses or data properties of the class Attributes?
the ontology is as follow:
<?xml version="1.0"?>
<!DOCTYPE Ontology [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.semanticweb.org/acer/ontologies/2014/1/untitled-ontology-56"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
ontologyIRI="http://www.semanticweb.org/acer/ontologies/2014/1/untitled-ontology-56">
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Declaration>
<Class IRI="#attributes"/>
</Declaration>
<Declaration>
<Class IRI="#capsule"/>
</Declaration>
<Declaration>
<Class IRI="#requirement"/>
</Declaration>
<Declaration>
<Class IRI="#service"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasAttribute"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasCapsule"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasRequirement"/>
</Declaration>
<Declaration>
<DataProperty IRI="#description"/>
</Declaration>
<Declaration>
<DataProperty IRI="#diskFree"/>
</Declaration>
<Declaration>
<DataProperty IRI="#diskFreeUnit"/>
</Declaration>
<Declaration>
<DataProperty IRI="#diskFreeValue"/>
</Declaration>
<Declaration>
<DataProperty IRI="#inputParameter"/>
</Declaration>
<Declaration>
<DataProperty IRI="#location"/>
</Declaration>
<Declaration>
<DataProperty IRI="#memoryFree"/>
</Declaration>
<Declaration>
<DataProperty IRI="#memoryFreeUnit"/>
</Declaration>
<Declaration>
<DataProperty IRI="#memoryFreeValue"/>
</Declaration>
<Declaration>
<DataProperty IRI="#numInstance"/>
</Declaration>
<Declaration>
<DataProperty IRI="#operationSystem"/>
</Declaration>
<Declaration>
<DataProperty IRI="#outputParameter"/>
</Declaration>
<Declaration>
<DataProperty IRI="#port"/>
</Declaration>
<Declaration>
<DataProperty IRI="#price"/>
</Declaration>
<Declaration>
<DataProperty IRI="#protocol"/>
</Declaration>
<Declaration>
<DataProperty IRI="#providerIdentifier"/>
</Declaration>
<Declaration>
<DataProperty IRI="#serviceIdentifier"/>
</Declaration>
<Declaration>
<DataProperty IRI="#type"/>
</Declaration>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#description"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#inputParameter"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#numInstance"/>
<Datatype abbreviatedIRI="xsd:integer"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#outputParameter"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#price"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#providerIdentifier"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#serviceIdentifier"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#attributes"/>
<DataAllValuesFrom>
<DataProperty IRI="#type"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#capsule"/>
<DataAllValuesFrom>
<DataProperty IRI="#location"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#capsule"/>
<DataAllValuesFrom>
<DataProperty IRI="#port"/>
<Datatype abbreviatedIRI="xsd:integer"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#capsule"/>
<DataAllValuesFrom>
<DataProperty IRI="#protocol"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#requirement"/>
<DataAllValuesFrom>
<DataProperty IRI="#diskFreeUnit"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#requirement"/>
<DataAllValuesFrom>
<DataProperty IRI="#diskFreeValue"/>
<Datatype abbreviatedIRI="xsd:integer"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#requirement"/>
<DataAllValuesFrom>
<DataProperty IRI="#memoryFreeUnit"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#requirement"/>
<DataAllValuesFrom>
<DataProperty IRI="#memoryFreeValue"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#requirement"/>
<DataAllValuesFrom>
<DataProperty IRI="#operationSystem"/>
<Datatype abbreviatedIRI="xsd:string"/>
</DataAllValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#service"/>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="#hasAttribute"/>
<Class IRI="#attributes"/>
</ObjectSomeValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#service"/>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="#hasCapsule"/>
<Class IRI="#capsule"/>
</ObjectSomeValuesFrom>
</SubClassOf>
<SubClassOf>
<Class IRI="#service"/>
<ObjectSomeValuesFrom>
<ObjectProperty IRI="#hasRequirement"/>
<Class IRI="#requirement"/>
</ObjectSomeValuesFrom>
</SubClassOf>
<SubDataPropertyOf>
<DataProperty IRI="#diskFreeUnit"/>
<DataProperty IRI="#diskFree"/>
</SubDataPropertyOf>
<SubDataPropertyOf>
<DataProperty IRI="#diskFreeValue"/>
<DataProperty IRI="#diskFree"/>
</SubDataPropertyOf>
<SubDataPropertyOf>
<DataProperty IRI="#memoryFreeUnit"/>
<DataProperty IRI="#memoryFree"/>
</SubDataPropertyOf>
<SubDataPropertyOf>
<DataProperty IRI="#memoryFreeValue"/>
<DataProperty IRI="#memoryFree"/>
</SubDataPropertyOf>
</Ontology>
<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->

As the question is written now, it's a little bit hard to tell what you asking, but if I understand you correctly, my impression is that you currently have two classes:
Service
Attribute
and that a service can be related to an Attribute by the hasAttribute property. In addition, each Attribute is described by some values for a number of properties:
serviceIdentifier (range: String)
type (range: String)
description (range: String)
inputParameter (range: unspecified)
outputParameter (range: unspecified)
price (range: integer)
That means that you might have data that looks something like this:
:service72 :hasAttribute _:attr1 .
_:attr1 rdf:type :Attribute .
_:attr1 :price 73 .
Unless you actually need to refer to instances of Attributes for some reason, this representation seems a bit more complicated than it needs to be. As to the particular question:
must we consider serviceidentifier, type, description, etc., as subclasses or data properties of the class Attributes?
You could declare, e.g., ServiceIdentifier as a subclass of Attribute, but if the important value for service provider is a string, then you'd still need a data property that relates instances of ServiceIdentifier to the string that actually identifies the service. That is, you'd end up with data like this:
:service72 :hasAttribute _:attr
_:attr rdf:type :ServiceIdentifier .
_:attr :hasServiceIdentifierString "service identification"
Object properties relate individuals to other individuals, and data properties relate individuals to literal data. If you make hasAttribute an object property, then Attributes must be individuals and different kinds of attributes could be subclasses of Attrbute, but you'll need data properties to relate the instances of Attribute to the actual attribute values.
I think you could just as easily make hasAttribute a data property, and then declare these properties as data properties that are subproperties of hasAttribute. That is, you'd have a property hierarchy like this:
hasAttribute (range: unspecified)
serviceIdentifier (range: string)
type (range: string)
description (range: string)
…
Then you can have data like this:
:service72 :serviceIdentifier "some identification" .
:service72 :type "my favorite service" .
:service72 :price 32 .
Then, because those properties are subproperties of hasAttribute, if you use a reasoner, you can still infer the following triples if you need them:
:service72 :hasAttribute "some identification" .
:service72 :hasAttribute "my favorite service" .
:service72 :hasAttribute 32 .
In general, it might not be a bad idea to use the least amount of structure necessary early on, and to refine your ontology as you make progress and need a bit more structure.

Related

How to use groups in testNG

I am implementing groups in the testng test suite.When I run my testng suite suite,it runs only the 'FireFox' test and when I put the tag in 'Firefox' test
it runs the 'IE' test.Kindly let me know what can be the reason for this??
<groups>
<run>
<include = "smoke"/>
</run>
</groups>
<classes>
<class name = "com.asw.beginner.tests.NewTest"/>
</classes>
</test>
<test name = "FireFox" allow-return-values = "true">
<parameter name = "browser" value = "FF"/>
<classes>
<class name = "com.asw.beginner.tests.NewTest"/>
</classes>
</test>
Define your test as following:
public class Test1 {
#Test(groups = { "functest" })
public void testMethod1() {
}
#Test(groups = {"functest", "checkintest"} )
public void testMethod2() {
}
#Test(groups = { "checkintest" })
public void testMethod3() {
}
}
Then you can use xml file as following
<test name="Test1">
<groups>
<run>
<include name="functest"/>
</run>
</groups>
<classes>
<class name="example1.Test1"/>
</classes>
</test>
Above test will only run the method with group functest.
You can read more about testng from Official testng documatation
Following is example java code
import org.testng.Assert; import org.testng.annotations.Test;
public class GroupTestExample { String message = ".com"; MessageUtil messageUtil = new MessageUtil(message);
#Test(groups = { "functest", "checkintest" })
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
message = ".com";
Assert.assertEquals(message, messageUtil.printMessage()); }
#Test(groups = { "checkintest" })
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "tutorialspoint" + ".com";
Assert.assertEquals(message, messageUtil.salutationMessage()); }
#Test(groups = { "functest" })
public void testingExitMessage() {
System.out.println("Inside testExitMessage()");
message = "www." + "tutorialspoint"+".com";
Assert.assertEquals(message, messageUtil.exitMessage()); } }
following is Testng.xml file
<groups>
<run>
<include name = "functest" />
</run>
</groups>
<classes>
<class name = "GroupTestExample" />
</classes>
</test> </suite>

Can we pass parameters or any attributes at method level in testng.xml?

// Testng xml
<test name="Test1" preserve-order ="true">
<parameter name="deviceName_" value="aaaa"/>
<classes>
<class name="Test">
<methods>
<include name="methodName"/>
</methods>
</class>
</classes>
</test>
// Can i pass parameters at method level like i passed deviceName at test level
Actually, parameters on method level exists. Here is an example:
<suite name="my-suite" verbose="1">
<test name="my-test">
<classes>
<class name="testng.ex1.TestParams">
<methods>
<include name="m1">
<parameter name="key1" value="val1"/>
<parameter name="key2" value="val2"/>
</include>
<include name="m2">
<parameter name="key1" value="valA"/>
<parameter name="key2" value="valB"/>
</include>
</methods>
</class>
</classes>
</test>
</suite>
and the test class is,
package testng.ex1;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParams {
#Test
#Parameters({ "key1", "key2" })
public void m1(String key1, String key2) throws Exception {
System.out.println(key1 + ", " + key2);
}
#Test
#Parameters({ "key1", "key2" })
public void m2(String key1, String key2) throws Exception {
System.out.println(key1 + ", " + key2);
}
}
another approach is to use a data-provider that fetches the keys from testng.xml. See example:
<suite name="my-suite" verbose="1">
<test name="my-test">
<classes>
<parameter name="keys" value="key1,key2,key3,key4" />
<class name="testng.ex2.TestParams" />
</classes>
</test>
</suite>
The test calss,
package testng.ex2;
import java.util.Arrays;
import java.util.List;
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParams {
#Test(dataProvider = "dp")
public void m1(Employee e) throws Exception {
System.out.println("name: " + e.getName() + ", age: " + e.getAge());
}
#DataProvider(name = "dp")
#Parameters("keys")
public Object[][] createData(ITestContext ctx) {
String keysString = ctx.getCurrentXmlTest().getLocalParameters().get("keys");
List<String> keys = Arrays.asList(keysString.split(","));
Object[][] result = new Object[keys.size()][1];
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
result[i] = new Object[] { new Employee(key) };
}
return result;
}
}
The employee class,
package testng.ex2;
public class Employee {
private final String name;
private final int age;
public Employee(String key) {
// use 'key' to lookup employee in database
name = key + "_name"; // dummy value
age = 41; // dummy value
}
String getName() {
return name;
}
int getAge() {
return age;
}
}
you can get the parameter in the before method as given below,
#BeforeMethod
#Parameters({ "key1", "key2" })
public void beforem1(String key1, String key2){
System.out.println(key1 + ", " + key2);
}

Re-Running TestNG tests not working for all the Tests

I am using IRetryAnalyzer interface to run failed test cases again. It works fine if I have only one Test in my TestNG XML file, however if I have multiple tests in my XML file it works only for the first test.
Root Cause: the retryCount for second test is set to 1, I am not sure how to reset it.
Existing open issue:
https://github.com/cbeust/testng/issues/1241
RetryAnalyzer.java
public class RetryAnalyzer implements IRetryAnalyzer {
private int retryCount = 0;
private int maxRetryCount = 1;
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
retryCount++;
return true;
}
return false;
}
}
AnnotationTransformer.java
public class AnnotationTransformer implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
annotation.setRetryAnalyzer(RetryAnalyzer.class); //to enable for all the methods.
}
}
TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="BrowserStack" >
<listeners>
<listener class-name="uk.co.gaurang.libs.ResultListener" />
<listener class-name="uk.co.gaurang.libs.AnnotationTransformer" />
</listeners>
<test name="IPhone6S">
<classes>
<class name="uk.co.gaurang.tests.Demo"/>
</classes>
</test>
<test name="IPhone6SPlus">
<classes>
<class name="uk.co.gaurang.tests.Demo"/>
</classes>
</test>
</suite>

I am getting null pointer exception while running testng code through XML.But when running code directly its working fine

Code is Grouping in TESTNG
package testNG_annot;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestNG_grp1
{
#BeforeMethod
public void CarBM() {
System.out.println("CarBM");
}
*** // Created group car and Two wheeler//***
#Test(groups = { "Car" })
public void Sedan1() {
System.out.println("Test1-Verna");
}
#Test(groups = { "Car" })
public void Sedan2() {
System.out.println("Test2-BMW");
}
#Test(groups = { "TwoWheeler" })
public void Scooter1() {
System.out.println("Test3-ScootyPep");
}
#Test(groups = { "TwoWheeler" })
public void aScooter2() {
System.out.println("Test4-TVS");
}
}
suite.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="grp11">
<test name="group1">
<gropus>
<run>
<include name="Car"/>
</run>
</gropus>
<classes>
<class name="testNG_annot.TestNG_grp1"/>
</classes>
</test>
</suite>
Your spelling for groups tag is wrong. Change the spelling and run it again.
<groups>
<run>
<include name="Car"/>
</run>
</groups>
Form the testng.xml file as below format. Run it as testng test and you will get your test running.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="Test" >
<classes>
<class name="testNG_annot.TestNG_grp1" />
</classes>
</test>
</suite>
Keep this on top in your xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

How to run TestNG tests one-by-one

I have a test suite and I want to run tests form XML file one-by-one. But when I'm running it, it runs all TCs at the same time (I have 3 open browsers at the same time).
My XML:
<suite name="TestingSuite" preserve-order="true" parallel="false" verbose="10">
<test name="Test1">
<classes>
<class name="guiAndFunctianal.LoginFail" />
<class name="guiAndFunctianal.LoginAsManager" />
<class name="guiAndFunctianal.CreateUserTest" />
</classes>
</test>
</suite>
My TCs looks like this:
public class LoginFail extends AbstractTest{
# BeforeTest
public void openBrowser() {
openBrowserFireFoxAllTcs();
}
# Test
public void main (){
}
# AfterTest
public void quit() {
driver.quit(); }
AbstractTest
public class AbstractTest {
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10);
public void openBrowserFireFoxAllTcs() {
driver.get("some URL");
}
I assume you want sequential execution. Open a browser>finish testing>close browser and then repeat the same for other browsers. If that's case I would do the following:
TestNG.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" junit="false" parallel="false" configfailurepolicy="skip" thread-count="5" skipfailedinvocationcounts="false" data-provider-thread-count="10" group-by-instances="false" preserve-order="true" allow-return-values="false">
<test name="firefox" junit="false" skipfailedinvocationcounts="false" preserve-order="true" group-by-instances="false" allow-return-values="false">
<parameter name="browser" value="firefox" />
<classes>
<class name="com.github.tests.GitHubHomePageTests" />
</classes>
</test>
<test name="ie" junit="false" skipfailedinvocationcounts="false" preserve-order="true" group-by-instances="false" allow-return-values="false">
<parameter name="browser" value="ie" />
<classes>
<class name="com.github.tests.GitHubHomePageTests" />
</classes>
</test>
<test name="chrome" junit="false" skipfailedinvocationcounts="false" preserve-order="true" group-by-instances="false" allow-return-values="false">
<parameter name="browser" value="chrome" />
<classes>
<class name="com.github.tests.GitHubHomePageTests" />
</classes>
</test>
</suite>
How I instantiate the drivers:
package com.github.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.*;
public class BaseTest {
public WebDriver driver;
String url = "https://github.com/";
#Parameters("browser")
#BeforeClass
public void SetUpTests(String browser) {
if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("ie")) {
System.setProperty("webdriver.ie.driver", ".\\drivers\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
}
//Navigate to url
driver.navigate().to(url);
//Maximize the browser window
driver.manage().window().maximize();
}
#AfterClass
public void CleanUpDriver() throws Exception {
// Quit current driver instance.
try {
driver.quit();
} catch (Exception ex) {
throw ex;
}
}
How the test run
package com.github.tests;
import com.github.pageobjects.GitHubLandingPage;
import org.testng.Assert;
import org.testng.annotations.Test;
public class GitHubHomePageTests extends BaseTest {#Test
public void ExploreLinkTest() {
String explorePageTitle = new GitHubLandingPage(driver)
.clickGitHubExplorePage()
.getGitHubExplorerPageTitle().trim();
System.out.println(explorePageTitle);
Assert.assertEquals(explorePageTitle, "Explore GitHub");
}
}
A global Github repo is available here
Try this:
<suite name="TestingSuite" preserve-order="true" thread-count="1" verbose="10">
<test name="Test1">
<classes>
<class name="guiAndFunctianal.LoginFail" />
</classes>
</test>
<test name="Test2">
<classes>
<class name="guiAndFunctianal.LoginAsManager" />
</classes>
</test>
<test name="Test3">
<classes>
<class name="guiAndFunctianal.CreateUserTest" />
</classes>
</test>
</suite>
Close your driver before quit:
# AfterTest
public void quit() {
driver.close()
driver.quit();
}