Base Class vs Extended Classes - selenium-webdriver

I'm a new learner, I'm practicing the base and child classes. My question is how do we decide which class should be instantiated, extended or the Baseclass?
Thanks in advance
package MavenProject2Package2;
import org.testng.annotations.Test;
import MavenProject2Package.JavaTesting;
public class JavaTesting2 extends JavaTesting
{
#Test
public void f1()
{
JavaTesting a1 = new JavaTesting();
System.out.println(a1.msg);
JavaTesting2 a2 = new JavaTesting2();
System.out.println(a2.msg);
}
}

Base class - it's a class which you should be extending from. - eg - superclass.
In superclass you may put some general fields and methods, which are used across your web app. For example, locators for header as well as footer items, because they are the same for all the pages (mostly).

Related

how to get range class of objectProperty by its domain class in owlapi?

In my project, I'd like to get all the range class related to the given class by an restricted(somevaluefrom or allvalues from) objectproperties. I can get the restricted subclassofAxioms expressions including the given class, but how can I get the range class in these expressions? In other word, how can I get all the related classes to the given class excluding inherited subclass.
For example:
public static void printSubClassOfAxioms(OWLOntology ontology,OWLReasoner reasoner,OWLClass owlClass){
for(OWLSubClassOfAxiom ax:ontology.getSubClassAxiomsForSubClass(owlClass)){
OWLClassExpression expression=ax.getSuperClass();
System.out.println(ax);
System.out.println(expression);
}
}
The results are:
SubClassOf(<#FourCheesesTopping> <#CheeseTopping>)
SubClassOf(<#FourCheesesTopping> ObjectSomeValuesFrom(<#hasSpiciness> <#Mild>))
SubClassOf(<#FourCheesesTopping> ObjectAllValuesFrom(<#hasCountryOfOrigin> #Country>))
How can I just get the range classes #Country and #Mild
Thank you for your attention!
Write an OWLObjectVisitor and override the visit(OWL... Type) for the restrictions you're interested in. At that point,
type.getFiller()
will yield the class you're after.
Examples are in the documentation: https://github.com/owlcs/owlapi/wiki/Documentation
public class RestrictionVisitor extends OWLClassExpressionVisitor {
#Override
public void visit(#Nonnull OWLObjectSomeValuesFrom ce) {
// This method gets called when a class expression is an existential
// (someValuesFrom) restriction and it asks us to visit it
}
}

Use of Wrapper class for deserialization in callout?

I found the following use of a wrapper class, and was wondering if it is a good practice or whether its just duplication of code for no reason.
//Class:
public class SomeClass{
public Integer someInt;
public String someString;
}
//Callout Class:
public class CalloutClass{
public SomeClass someMethod(){
//...code to do a callout to an api
SomeClass someClassObj = (SomeClass)JSON.Deserialize(APIResponse.getBody(), SomeClass.class);
return someClassObj;
}
}
//Controller:
public class SomeController {
public SomeController(){
someClassObj = calloutClassObj.someMethod();
SomeWrapper wrapperObj = new SomeWrapper();
for(SomeClass iterObj : someClassObj){
wrapperObj.someWrapperInt = iterObj.someInt;
wrapperObj.someWrapperString = iterObj.someString;
}
}
public class someWrapper{
public Integer someWrapperInt{get;set;}
public String someWrapperString{get;set;}
}
}
The wrapper class "someWrapper" could be eliminated if we just use getters and setters ({get;set;}) in "SomeClass."
Could anyone explain if there could be a reason for following this procedure?
Thanks,
James
My assumption (because, code in controller is extra pseudo) is
SomeClass is a business entity, purpose of which is to store/work with business data. By work I mean using it's values to display it (using wrapper in controller), to calculate smth in other entities or build reports... Such kind of object should be as lightweight as possible. You usually iterate through them. You don't need any methods in such kind of objects. Exception is constructor with parameter(s). You might want to have SomeObject__c as parameter or someWrapper.
someWrapper is a entity to display business entity. As for wrapper classes in controllers. Imagine, that when you display entity on edit page and enter a value for someWrapperInt property, you want to update someWrapperString property (or you can just put validation there, for example, checking if it is really Integer). Usually, as for business entity, you don't want such kind of functionality. But when user create or edit it, you may want smth like this.

How do I have every test in class automatically tagged with a specific tag

I am using the flatspec trait to create my tests and I would like to create a base class that would automatically tag any tests in that class with a particular tag.
For example, any tests in classes that inherit from the IntegrationTest class would automatically be appropriately tagged. So instead of:
class ExampleSpec extends FlatSpec {
"The Scala language" must "add correctly" taggedAs(IntegrationTest) in {
val sum = 1 + 1
assert(sum === 2)
}
I would like do this and still have the test tagged as an IntegrationTest
class ExampleSpec extends IntegrationSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
Thanks!
If you're willing to use a direct annotation on the test class, rather than a parent class, you can use the example at https://github.com/kciesielski/tags-demo. Adapted somewhat for your example, you need to declare a Java class:
package tags;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
#org.scalatest.TagAnnotation
#Retention(RUNTIME)
#Target({METHOD, TYPE})
public #interface MyAnnotation {
}
Then you use it to annotate the Scala test class:
#tags.MyAnnotation
class ExampleSpec extends FlatSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
You then have to use the actual string tags.MyAnnotation to specify the tag you want run (or ignored).
I tried to annotate a parent class instead, but I can't get it to work. I could imagine it being a significant problem for you or not, depending on what else you're trying to do.
Actually, the online doc for the org.scalatest.Tag class does a fair job of describing all this, although I say it after getting it to work by following the above project on GitHub..
Since ScalaTest 2.2.0 tags can be inherited (http://www.scalatest.org/release_notes/2.2.0).
Add #Inherited to your annotation definition.
package tags;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
**#Inherited**
#org.scalatest.TagAnnotation
#Retention(RUNTIME)
#Target({METHOD, TYPE})
public #interface RequiresIntegrationStuff {
}
Annotate your base spec.
#RequiresIntegrationStuff
class IntegrationSpec extends FlatSpec {}
Just use your base spec as a base class.
class ExampleSpec extends IntegrationSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
After that, ExampleSpec will be tagged as tags.RequiresIntegrationStuff.
You will find working project here: https://github.com/wojda/tags-demo (based on https://github.com/kciesielski/tags-demo from Spiro Michaylov's answer)

Nancy/TinyIoC multiple concrete classes for single interface

We have two auth methods for different modules – UserAuthModule and ServiceAuthModule. We’ve created 2 base classes that modules derive from. We’ve interfaced the AuthProviders into IAuthProvider. Then we have a dependency in the constructors that should get the correct AuthProvider injected. However, we can’t find a way to tell Nancy/TinyIoC which concrete class to use. Here is the pseudo-code:
abstract class UserAuthModule : NancyModule
{
public UserAuthModule(IAuthProvider authProvider) // should get the UserAuthProvider concrete class
}
abstract class ServiceAuthModule : NancyModule
{
public ServiceAuthModule(IAuthProvider authProvider) // should get the ServiceAuthProvider concrete class
}
Here's an example of one of the concrete module's class declaration:
public class AccountModule : UserAuthModule
We then get stuck: how do we register 2 concrete classes for the IAuthProvider interface? We could name them, but can’t figure out how Nancy knows which class to inject when it does the constructor injection.
Inside our bootstrapper we have:
Container.Register<IAuthProvider, UserAuthProvider>(“UserAuth”);
Container.Register<IAuthProvider, ServiceAuthProvider>(“ServiceAuth”);
We could resolve the type from the container, but there's not container access within the Nancy module.
Is creating a unique interface for each based off of IAuthProvider out of the question?
interface IUserAuthProvider : IAuthProvider { }
interface IServiceAuthProvider : IAuthProvider { }
And then register:
Container.Register<IUserAuthProvider, UserAuthProvider>();
Container.Register<IServiceAuthProvider, ServiceAuthProvider>();
And then modify the constructors:
public UserAuthModule(IUserAuthProvider authProvider)
public ServiceAuthModule(IServiceAuthProvider authProvider)

Importing a class with a specific parameter

I got a ViewModel which I export with MEF. I'd like this ViewModel to be initialized differently each time it's being imported, according to an enum/specific object parameter that will be provided to it.
I've been reading a little on the subject and I found that maybe this -
http://msdn.microsoft.com/en-us/library/ee155691.aspx#metadata_and_metadata_views
would be able to fit my needs, but I'm not sure that this would be the best way to do it.
Another method I've been thinking about is importing the class normally, and then once I've an instance, to call a special initialization method that would receive my parameter. However this doesn't seem like a classic MEF implementation, and maybe losses some of its "magic".
I'm hoping someone would be able to point out for me what would be the recommended method to achieve this.
Thanks!
A workaround is exporting a factory that creates instances of your type. While this means you cannot directly import thos instances, it does have the benefit that the logic to create them is the responsability of the factory so users of the class do not have to know about it:
public class ServiceWithParameter
{
public ServiceWithParameter( int a )
{
this.a = a;
}
private readonly int a;
}
[Export]
public class ServiceWithParameterFactory
{
public ServiceWithParameterFactory()
{
instance = 0;
}
public ServiceWithParameter Instance()
{
return new ServiceWithParameter( instance++ );
}
private int instance;
}
//now everywhere you need ServiceWithParameter:
[Import]
ServiceWithParameterFactory serviceFactory;
var instanceA = serviceFactory.Instance(); //instanceA.a = 0
var instanceB = serviceFactory.Instance(); //instanceB.a = 1
A more extensible way is telling the container you have a factory and an example is presented here: http://pwlodek.blogspot.com/2010/10/mef-object-factories-using-export.html

Resources