I try to write a Contract in Kotlin Corda-tranning Repository with TDD. All IOUIssueTests was Failed.
I have jdk 1.8.0_211. Gradle 5.5. And installed kotlin plugin. IOUStates were also implemented.
This is my IOUContract for 5 IOUIssueTest:
package net.corda.training.contract
import net.corda.core.contracts.*
import net.corda.core.transactions.LedgerTransaction
import net.corda.training.state.IOUState
/**
* This is where you'll add the contract code which defines how the [IOUState] behaves. Look at the unit tests in
* [IOUContractTests] for instructions on how to complete the [IOUContract] class.
*/
#LegalProseReference(uri = "<prose_contract_uri>")
class IOUContract : Contract {
companion object {
#JvmStatic
val IOU_CONTRACT_ID = "net.corda.training.contract.IOUContract"
}
/**
* Add any commands required for this contract as classes within this interface.
* It is useful to encapsulate your commands inside an interface, so you can use the [requireSingleCommand]
* function to check for a number of commands which implement this interface.
*/
interface Commands : CommandData {
class Issue : TypeOnlyCommandData(), Commands
}
/**
* The contract code for the [IOUContract].
* The constraints are self documenting so don't require any additional explanation.
*/
override fun verify(tx: LedgerTransaction) {
val command = tx.commands.requireSingleCommand<Commands>()
when (command.value) {
is Commands.Issue -> {
requireThat {
"No inputs should be consumed when issuing an IOU." using (tx.inputs.isEmpty())
"Only one output state should be created when issuing an IOU." using (tx.outputs.size == 1)
val iou = tx.outputStates.single() as IOUState
"A newly issued IOU must have a positive amount." using (iou.amount.quantity > 0)
"The lender and borrower cannot have the same identity." using (iou.lender !== iou.borrower)
"Both lender and borrower together only may sign IOU issue transaction." using(iou.participants.toSet() == iou.participants.map { it.owningKey}.toSet())
}
}
}
}
}
However, when I run IOUIsuueTest.kt I get the following error:
java.lang.IllegalArgumentException: Attempted to find dependent attachment for class net/corda/core/contracts/TypeOnlyCommandData, but could not find a suitable candidate.
at net.corda.core.transactions.TransactionBuilder.addMissingDependency(TransactionBuilder.kt:179)
at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core(TransactionBuilder.kt:160)
at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core$default(TransactionBuilder.kt:128)
at net.corda.core.transactions.TransactionBuilder.toWireTransaction(TransactionBuilder.kt:125)
at net.corda.testing.dsl.TestTransactionDSLInterpreter.toWireTransaction$test_utils(TestDSL.kt:95)
at net.corda.testing.dsl.TestLedgerDSLInterpreter.recordTransactionWithTransactionMap(TestDSL.kt:257)
at net.corda.testing.dsl.TestLedgerDSLInterpreter._transaction(TestDSL.kt:289)
at net.corda.testing.dsl.LedgerDSL._transaction(LedgerDSLInterpreter.kt)
at net.corda.testing.dsl.LedgerDSL.transaction(LedgerDSLInterpreter.kt:141)
at net.corda.testing.dsl.LedgerDSL.transaction$default(LedgerDSLInterpreter.kt:139)
at net.corda.training.contract.IOUIssueTests$mustIncludeIssueCommand$1.invoke(IOUIssueTests.kt:57)
at net.corda.training.contract.IOUIssueTests$mustIncludeIssueCommand$1.invoke(IOUIssueTests.kt:21)
at net.corda.testing.node.NodeTestUtils$ledger$2.invoke(NodeTestUtils.kt:39)
at net.corda.testing.node.NodeTestUtils$ledger$2.invoke(NodeTestUtils.kt)
at net.corda.testing.internal.InternalTestUtilsKt$withTestSerializationEnvIfNotSet$1.invoke(InternalTestUtils.kt:214)
at net.corda.testing.internal.InternalTestUtilsKt$withTestSerializationEnvIfNotSet$1.invoke(InternalTestUtils.kt)
at net.corda.testing.common.internal.CommonSerializationTestHelpersKt.asContextEnv(CommonSerializationTestHelpers.kt:11)
at net.corda.testing.internal.InternalSerializationTestHelpersKt.asTestContextEnv(InternalSerializationTestHelpers.kt:33)
at net.corda.testing.internal.InternalSerializationTestHelpersKt.asTestContextEnv$default(InternalSerializationTestHelpers.kt:31)
at net.corda.testing.internal.InternalTestUtilsKt.withTestSerializationEnvIfNotSet(InternalTestUtils.kt:214)
at net.corda.testing.node.NodeTestUtils.ledger(NodeTestUtils.kt:36)
at net.corda.testing.node.NodeTestUtils.ledger$default(NodeTestUtils.kt:23)
at net.corda.training.contract.IOUIssueTests.mustIncludeIssueCommand(IOUIssueTests.kt:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.
java:66)
Error has been fixed. I have used kotlin unit test.Kotlin Unit Test
I have a database table with 270 columns I need to work with. I wrote some code generators to help me keep my sanity, but I have an issue with ItemViewModel class - it refuses to compile with 'Method code too large' exception.
The class is plain:
class F321PModel: ItemViewModel<F321P>() {
val id = bind(F321P::idProperty)
// 269 more lines below
I receive method too large exception even for 50 columns. Is bind introduces so huge overhead ? I don't think that 50 columns table is something extreme, maybe it is possible to optimize something ?
Here is problem classes https://gist.github.com/anonymous/d0978899ad569839797b025ad081bbf7
Error:Kotlin: [Internal Error] java.lang.RuntimeException: Error generating class file ru/abinet/blt/updateapplication/models/F321PModel.class (compiled from [C:\Users\hachatryan\IdeaProjects\updateapplication\src\main\kotlin\ru\abinet\blt\updateapplication\models\321PModel.kt]): Method code too large!
at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:255)
at org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.writeAll(outputUtils.kt:32)
at org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.writeAll(outputUtils.kt:42)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.writeOutput(KotlinToJVMBytecodeCompiler.kt:98)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.access$writeOutput(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:259)
at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:258)
at org.jetbrains.kotlin.codegen.state.GenerationState.afterIndependentPart(GenerationState.kt:215)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:67)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.generatePackage(KotlinCodegenFacade.java:100)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:78)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:45)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:450)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:152)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:380)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:892)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:919)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:891)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:378)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Method code too large!
at org.jetbrains.org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2036)
at org.jetbrains.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:850)
at org.jetbrains.kotlin.codegen.ClassBuilderFactories$2.asBytes(ClassBuilderFactories.java:126)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.ClassFileFactory$ClassBuilderAndSourceFileList.asBytes(ClassFileFactory.java:287)
at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:252)
... 45 more
I've come across this same error with ~60 properties, I managed to get around it by wrapping each bind call in a lazy delegate:
val id: LongProperty by lazy<LongProperty> {
bind(F321P::idProperty)
}
I'm trying to store an entity in my database in an async method by returning a CompletableFuture<>. The code works fine as long as I do not check the state of the future (e.g isComplete() or .get()).
CompletableFuture<Product> working = serviceTest.test("working");
The above example works, the product is stored in the database.
#Async
public CompletableFuture<Product> test(String name)
{
Product p = new Product();
p.setId(new Random().nextInt(500000));
p.setName(name);
logger.info("Saving "+ name);
p = productRepository.save(p);
logger.info("finished " + name);
return CompletableFuture.completedFuture(p);
}
However, as soon as I change the code to for example
CompletableFuture<Product> notWorking = serviceTest.test("notWorking");
notWorking.get();
The entity is not saved and the code freezes at 'productRepository.save(p);'.
What is the correct way to save entities in an async method? Note that this is a simplified example and in the real scenario the test function is a long running operation to fetch a list of products from an external server.
The not explainable issue for me is that a simple method to get the state of the future blocks the saving of my entity.
I extracted a thread dump when the deadlock occurs. This is the relevant part
"MigrationTask-1" #19 prio=5 os_prio=0 tid=0x00007fbdd4bcd800 nid=0x16ea waiting for monitor entry [0x00007fbda9274000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:187)
- waiting to lock <0x00000000850ab208> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:389)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:177)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:89)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:66)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineQualifiedTransactionManager(TransactionAspectSupport.java:382)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:363)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy96.save(Unknown Source)
I am using Selenium to Test my User Interface.
I am trying to use the #FindBy-Annotation. The following piece of code works fine:
#FindBy(how=How.XPATH, xpath ="//input[contains(#id,'idOfInputField')]")
private WebElement someWebElement;
private void someMethod(){
WebElement a = someWebElement.findElement(By.xpath("//a[contains(#class, 'ui-spinner-up')][1]"));
WebElement span1 = a.findElement(By.xpath("//a[contains(#class, 'ui-spinner-up')][1]"));
WebElement span2 = span1.findElement(By.xpath("//span[contains(#class, 'ui-button-text')][1]"));
WebElement b = span2.findElement(By.xpath("//span[contains(#class,'ui-icon ui-icon-triangle-1-n')]"));
b.click();
}
I would like to use the following code, because it is Annotation-based, but it doesnt work, although I think it is exactly the same:
#FindBy(how=How.XPATH, xpath ="//input[contains(#id,'idOfInputField')]"
+ "//a[contains(#class, 'ui-spinner-up')][1]"
+ "//a[contains(#class, 'ui-spinner-up')][1]"
+ "//span[contains(#class, 'ui-button-text')][1]"
+ "//span[contains(#class,'ui-icon ui-icon-triangle-1-n')]")
private WebElement someWebElement;
pivate void someMethod(){
someWebElement.click();
}
What I get is the following exception:
java.lang.RuntimeException: Cannot invoke click on element null. Cannot find it.
Cause: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//input[contains(#id,'idOfInputField')]//a[contains(#class, 'ui-spinner-up')][1]//span[contains(#class, 'ui-button-text')][1]//span[contains(#class,'ui-icon ui-icon-triangle-1-n')]"}
Command duration or timeout: 14 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.32.0', revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb', time: '2013-04-09 10:39:28'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.5.0-28-generic', java.version: '1.7.0_21'
Session ID: 92f605a1-0a63-4ba0-b290-ca724b3c6386
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=20.0}]
at path.to.package.utils.StaleReferenceAwareFieldDecorator$StaleReferenceAwareElementLocator.in
voke(StaleReferenceAwareFieldDecorator.java:86)
at com.sun.proxy.$Proxy9.click(Unknown Source)
at
....
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Can some body explain whats the reason for this behavious or if there is actually a difference between those two pieces of code?
First of all, you cannot use such a convoluted xpath, that kills the readability of your page objects. Your selectors should be as much concise as possible. Secondly, you should not use XPATH and use CSS selector. Now coming back to your question,
#FindBy(css="span[class*='ui-icon-triangle-1-n']")
WebElement b;
or try
#FindBy(css="span[class*='ui-button-text']>span[class*='ui-icon-triangle-1-n']")
WebElement b;
EDIT: You have two XPath selectors of //a[contains(#class, 'ui-spinner-up')][1] in your first example, but only one in your second...that may be causing your problem.
The #FindBy annotation is used by the PageFactory class via the .initObjects method to load annotations. I use this method a lot if my page object implements the LoadableComponent interface by extending LoadableComponent . (NOTE: Of course, by extending LoadableComponent you cannot extend another class by your page object, but if you use static methods in a implemented interface, a JDK8 feature, then you can get functionality similar to extending multiple classes, or like traits/mixins .)
Page objects require the objects to be decorated. I think you are getting this error because you are not decorating the required class. Use the method initElements(yourdriverobject, classToBeDecorated). This should solve the problem. Let me know if you require any help.
I am new to H2 database, I ran into a particular problem where I was running a function named format.
public static String format(Double sumValue,Integer decimalValue){
if(sumValue==null)
return null;
else{
//format in particular order.
}
}
There are chances of sumValue getting null value.
when I am running a query it is throwing a following exception
SELECT format(commamount,2) as formatted FROM pshipcommdetail [90105-153]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:156)
at org.h2.message.DbException.convertInvocation(DbException.java:295)
at org.h2.engine.FunctionAlias$JavaMethod.getValue(FunctionAlias.java:405)
at org.h2.expression.JavaFunction.getValue(JavaFunction.java:38)
at org.h2.expression.Alias.getValue(Alias.java:35)
at org.h2.command.dml.Select.queryFlat(Select.java:519)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:614)
at org.h2.command.dml.Query.query(Query.java:269)
at org.h2.command.dml.Query.query(Query.java:239)
at org.h2.command.dml.Query.query(Query.java:37)
at org.h2.command.CommandContainer.query(CommandContainer.java:78)
at org.h2.command.Command.executeQuery(Command.java:181)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:278)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:137)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at reports.functions.Format.format(Format.java:15)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.h2.engine.FunctionAlias$JavaMethod.getValue(FunctionAlias.java:393)
I went through the documentation and was able to figure out that the aruguments should be of wrapper class hence I changed to double!
Can anyone of you please help me to figure out where the actual problem is?
Thanking you
With Regards
Phani Kumar
This question was answered on the H2 mailing list:
http://groups.google.com/group/h2-database/browse_thread/thread/a4105b923d79bf28#
It was a bug in Phani's code.