net.thucydides.core.webdriver.DriverConfigurationError: Could not instantiate class io.appium.java_client.AppiumDriver - appium

Could not instantiate new WebDriver instance of type class io.appium.java_client.AppiumDriver (class org.openqa.selenium.Platform$22 cannot be cast to class java.lang.String (org.openqa.selenium.Platform$22 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')). See below for more details.

Related

How to test with DomainUnitTest when multiTenancy

How do test domain classes when I use multiTenancy?
I can see that I need to extend with HibernateSpec and overwrite getConfiguration.
This goes okay when I use ServiceUnitTest but not for DomainUnitTest
Simple example:
application.yml is setup with:
grails:
gorm:
multiTenancy:
mode: DISCRIMINATOR
tenantResolverClass: security.CompanyTenantResolver
My test:
class TestSpec extends HibernateSpec implements DomainUnitTest<Test>{
void "expect ok test"() {
expect:
true
}
def setup() {
System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'unit-test')
}
def cleanup() {
System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '')
}
#Override
Map getConfiguration() {
[(Settings.SETTING_MULTI_TENANT_RESOLVER_CLASS): SystemPropertyTenantResolver]
}
}
No matter what I try i get:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.beans.ConstraintsEvaluator': Cannot resolve reference to bean 'grailsDomainClassMappingContext' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.mapping.simple.SimpleMapDatastore]: Constructor threw exception; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<?>]
Is it a error in grails or have forgotten something?
it is a error in grails version 3.3.2 works okay in version 3.3.0

Force #GrailsCompileStatic check request as AbstractMultipartHttpServletRequest

I'm trying to apply #GrailsCompileStatic to controller that has an action that retrieves MultipartFiles from request:
request.getFile('foo')
But get the following:
[Static type checking] - Cannot find matching method
javax.servlet.http.HttpServletRequest#getFile(java.lang.String)
Is there any chance to force compiler to verify request against AbstractMultipartHttpServletRequest (that has the getFile(java.lang.String) method) instead of HttpServletRequest?
UPD
This solution works:
MultipartFile multipartFile = ((StandardMultipartHttpServletRequest) request).getFile('myFile')
But has some strange behaviour when trying to test it:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot
cast object
'org.grails.plugins.testing.GrailsMockHttpServletRequest#2bcf856f'
with class 'org.grails.plugins.testing.GrailsMockHttpServletRequest'
to class
'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest'
http://docs.grails.org/2.2.1/api/org/codehaus/groovy/grails/plugins/testing/GrailsMockHttpServletRequest.html
and
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/support/StandardMultipartHttpServletRequest.html
both implements an interface
org.springframework.web.multipart.MultipartHttpServletRequest
so just use this
import org.springframework.web.multipart.MultipartHttpServletRequest
...
MultipartFile multipartFile = ((MultipartHttpServletRequest) request).getFile('myFile')

How to make #Autowired work in a regular class?

Here's what I've got:
#Component
class FooController {
fun createFoo() {
val foo = FooEntity()
foo.name = "Diogo"
fooRepository.save(foo)
}
#Autowired
internal lateinit var fooRepository: FooRepository
}
When trying to call createFoo(), I get the following error:
kotlin.UninitializedPropertyAccessException: lateinit property fooRepository has not been initialized
I thought that adding a #Component at the top would make my class discoverable by Spring and hence make #Autowired work, but maybe I got it wrong?
Just adding #Component to the class is not enough.
1) When you use #Component you have to make sure that the class is scanned by a component scan. It depends on how you bootstrap your applciation, but you can use <context:component-scan base-package="com.myCompany.myProject" /> for XML config or #ComponentScan for java configuration.
If you're using Spring boot - you don't need to declare #ComponentScan yourself, because #SpringBootApplication inherits it and by default it scans all the classes in the current package and all it's sub packages.
2) You have to get the bean from the spring context. Creating an object with new will not work.
Basically there are two ways to get a bean from the application context:
If you have an access to the ApplicationContext object then you can do something like this:
ApplicationContext ctx = ...;
MyBean mb = ctx.getBean(MyBean.class);//getting by type
Any spring bean that's declared in the context can access the other beans using dependency injection (#Autowired)
So I'm very new to Spring and was trying to call FooController by creating a instance of it through new instead of #Autowireing everywhere. When I added FooController as a dependency of the class it was being called from, it worked.

Spring data neo4j not creating unique indexes/constraints in Grails

I'm having some trouble getting unique constraints working with spring-data-neo4j in grails.
I suspect that it's because I've not wired it in properly, but the repository is being scanned and wired, and CRUD is working, so I'm not sure what I've done wrong.
I'm using grails 2.4.3, with these dependencies:
neo4jVerison="2.1.5"
dependencies {
compile("org.neo4j:neo4j-community:$neo4jVerison")
compile("org.neo4j.app:neo4j-server:$neo4jVerison")
compile("org.neo4j:neo4j-rest-graphdb:2.0.1")
compile("org.neo4j:neo4j-spatial:0.13-neo4j-2.1.4")
compile 'org.springframework.data:spring-data-neo4j:3.2.1.RELEASE'
test group:"org.neo4j", name:"neo4j-kernel", version: "$neo4jVerison", classifier:"tests"
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
test "xmlunit:xmlunit:1.5"
}
and these beans for my test environment:
testGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)
graphDb(GraphDatabaseService) { bean ->
bean.factoryBean = "testGraphDatabaseFactory"
bean.factoryMethod = "newImpermanentDatabase"
bean.destroyMethod = "shutdown" }
xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
neo4j.'repositories'( 'base-package': "repositories" )
neo4jTemplate(Neo4jTemplate, graphDb)
neo4jMappingContext(Neo4jMappingContext)
tx(NeoTransactions, graphDb)
The tx class just exposes a 'tx.tx { closure }' method that starts a graphDb transaction, and closes it even if the closure fails.
My domain class is:
package repositories
import org.springframework.data.neo4j.annotation.GraphId
import org.springframework.data.neo4j.annotation.Indexed
import org.springframework.data.neo4j.annotation.NodeEntity
#NodeEntity
class Junction {
#GraphId Long id;
#Indexed(unique = true) Long legacyId
}
and the repository is:
package repositories
import org.springframework.data.neo4j.repository.GraphRepository
interface JunctionRepository extends GraphRepository<Junction> {}
Given all of that, I would expect this to fail:
package repositories
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.data.neo4j.conversion.Result
class JunctionRepositoryIntegrationSpec extends RepositorySpecification {
JunctionRepository junctionRepository
def tx
def "should not be able to create two junctions with the same legacyId"() {
given: "some junctions with the same id"
Junction j = new Junction(legacyId: 10)
Junction j2 = new Junction(legacyId: 10)
when: "both are saved"
tx.tx {
[j, j2].each { junctionRepository.save(it) }
}
then:
1 == junctionRepository.count()
when: "the second one is changed to have the same legacy id"
def j3 = new Junction(legacyId: 11)
tx.tx {
junctionRepository.save(j3)
j3.legacyId = 10
junctionRepository.save(j3)
}
then: "an exception should be thrown"
thrown DataIntegrityViolationException
}
}
Strangely although only one junction was saved (i.e. 1 == junctionRepository.count()) the exception wasn't thrown when I try and save the modified j3.
Additionally, when I open the database in the Neo4J web console and run :schema it doesn't appear as if any indexes/constraints have been created.
I'm guessing that my wiring is not configured correctly, as I believe that the indexes should be setup when the domain object is parsed at wiring time.
Does anyone know what's missing please?
FOLLOW-UP 1:
I suspect that I should not be creating a template or mapping context by hand. The canonical spring configuration appears to be <neo:config/>.
However, I get a strange error when I try and do that through the spring dsl:
xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
neo4j.'repositories'( 'base-package': "repositories" )
neo4j.'config'( 'graphDatabaseService': "graphDb" )
The error is:
| Error Fatal error running tests: Error creating bean with name 'junctionRepository':
Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'neo4jTemplate' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.Neo4jMappingContext org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jMappingContext() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityIndexCreator' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.EntityIndexCreator org.springframework.data.neo4j.config.Neo4jConfiguration.entityIndexCreator() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexProvider' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.index.IndexProvider org.springframework.data.neo4j.config.Neo4jConfiguration.indexProvider() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'graphDatabaseService' is defined (Use --stacktrace to see the full trace)
Hmm: No bean named 'graphDatabaseService' is defined? Is that a bug? neo4j.'config'( 'graphDatabaseService': "graphDb" ) tells it to use the graphDb bean, doesn't it?
FOLLOW-UP 2:
If I change the bean name to graphDatabaseService it works fine. Looks like neo4j.config isn't passing the named graphDb bean to all of those that it constructs. :)
Yes it does rely on the name graphDatabaseService (unfortunately).
Also make sure that your tx class also calls tx.success() not just tx.close()

Class cannot be used as type parameter in the generic type or method, there is no implicit reference conversion

I am building (attempting to build) generic Repository, Task, and Controllers for my MVC 4 project and using it to learn generics and interfaces. I've gotten pretty far, but stuck on this error. CustomerContactsListViewModel does inherit from IViewModelList, which is why I am perplexed.
Error:
The type 'OTIS.AppServ.OrderMgmt.ViewModels.CustomerContactsListViewModel' cannot be used as type parameter 'TViewModelList' in the generic type or method 'OTIS.AppServ.BaseAppServGrid<TRepository,TViewModelSingle,TViewModelList>'. There is no implicit reference conversion from 'OTIS.AppServ.OrderMgmt.ViewModels.CustomerContactsListViewModel' to 'OTIS.AppServ.IViewModelList<OTIS.domain.OrderMgmt.Customer,OTIS.AppServ.OrderMgmt.ViewModels.CustomerContactsListViewModel>'.
The interface:
public interface IViewModelList<TClass, TViewModelList>
{
IEnumerable<TClass> ConvertViewModelToClass(IEnumerable<TViewModelList> entityList);
IEnumerable<TViewModelList> ConvertClassToViewModel(IEnumerable<TClass> entityList);
}
The View Model that inherits the Interface:
public class CustomerContactsListViewModel : IViewModelList<CustomerContact, CustomerContactsListViewModel>, IEntity
Generic Task (Application Services) class being inherited:
public class BaseAppServGrid<TRepository, TViewModelSingle, TViewModelList> : BaseAppServ<TRepository, TViewModelSingle>
where TRepository : class, IEntity, IAuditStamps, new()
where TViewModelSingle : class, IViewModelSingle<TRepository, TViewModelSingle>, new()
where TViewModelList : class, IEntity, IViewModelList<TRepository, TViewModelList>, new()
The specific Task/App services class trying to inherit the Base, which throws the error:
public class ManageCustomersAppServ : BaseAppServGrid<Customer, CustomerViewModel, CustomerContactsListViewModel>
In the CustomerContactsListViewModel you have implemented the first parameter of IViewModelList to be of type CustomerContact.
However, the class ManageCustomersAppServ has been declared with type Customer.
So
IViewModelList<Customer, CustomerContactsListViewModel>
is not assignable to
IViewModelList<CustomerContact, CustomerContactsListViewModel>
You need to either:
Change BaseAppServGrid to take another generic parameter like so:
public class BaseAppServGrid<TModel, TRepository, TViewModelSingle, TViewModelList> :
BaseAppServ<TRepository, TViewModelSingle>
where TRepository : class, IEntity, IAuditStamps, new()
where TViewModelSingle : class, IViewModelSingle<TRepository, TViewModelSingle>, new()
where TViewModelList : class, IEntity, IViewModelList<TModel, TViewModelList>, new()
public class ManageCustomersAppServ : BaseAppServGrid<CustomerContact, Customer, CustomerViewModel, CustomerContactsListViewModel>
Review whether Customer and CustomerContact can derive from some IRepository interface/class, if that was your intention when you passed Customer to a generic param called "TRepository".

Resources