How to use org.scalatest.Suite - scalatest

I'm trying to use scalatest suite using intellij idea like this :
class SampleTest extends org.scalatest.Suite {
def myTest() {
assert(true)
}
}
(new SampleTest).execute()
I have added scalactic_2.11 and scalactic_2.11 to my pom file.The problem is that the SDK still cant resolve it.

Well it seems the problem is due to versioning. using the following version resolved the issue :
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest</artifactId>
<version>0.9.5</version>
</dependency>

Related

java.lang.NoClassDefFoundError: feign/Request$Body in feign while adding support for multipart/form-data

I am trying to proxy multipart request via feign.
#PostMapping(value = "{pathUri1}/{pathUri2}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<BaseResponse<?>> uploadFileCall(#PathVariable(value = "pathUri1") String pathUri1, #PathVariable(value = "pathUri2") String pathUri2, #RequestPart(name = "file") MultipartFile file, #RequestParam Map<Object,Object> requestParam, #RequestHeader HttpHeaders httpHeaders);
this is service call.
#Configuration
class MultipartSupportConfig {
#Autowired
ObjectFactory<HttpMessageConverters> messageConverters;
#Bean
#Primary
#Scope("prototype")
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
added encoder config for multipart/form-data .
I have followed this
https://github.com/OpenFeign/feign-form
But I am getting hystrixRunTimeException which is caused because of
java.lang.NoClassDefFoundError: feign/Request$Body error.
Use feign-form-spring 3.4.1 version.
Gradle
compile(group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '3.4.1')
Maven
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.4.1</version>
</dependency>
Check requirements https://github.com/OpenFeign/feign-form#requirements
According to the open-feign's github document, Please Note the feign-form's versions:
all feign-form releases before 3.5.0 works with OpenFeign 9.* versions;
starting from feign-form's version 3.5.0, the module works with OpenFeign 10.1.0 versions and greater.
The following config works for me:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>${feign.version}</version>
</dependency>
Where:
<feign.version>11.0</feign.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>

Spring AOP No visible constructors in class

Error: java.lang.IllegalArgumentException: No visible constructors in class org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$DefaultObjectMapperCustomizer
Mostly, I used example given in link, and the following code can be found at github repository
Annotation:
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.TYPE)
public #interface NeedTestClass {
}
Aspect:
#After("#args(NeedTestClass)")
public void afterReturningAtArgs() {
log.info("aspect: after #args {}");
}
Service:
#Slf4j
#Component
public class BusinessService {
public void logicWithAnnotatedArgs1(Child c) {
log.info("service");
}
}
Pojo (top class, not sub class):
#NoArgsConstructor // tried with or without
#NeedTestClass
public class Child {}
Test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration
#WebAppConfiguration
#SpringBootTest
public class AopTest {
#Autowired
private BusinessService myBusinessService;
#Test
public void testAtArgsPCD() {
myBusinessService.logicWithAnnotatedArgs1(new Child());
}
I attempted to examine aop and annotated class inheritance, but it seems the first step could not be ok. I have tried #annotation() and this() PCD both ok.
EDIT:
So far I am wondering maybe the error is related with the bean loading sequence.
Your GitHub project does not even compile. Have you even tested it? First by trial and error I had to add all of these dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba.druid</groupId>
<artifactId>druid-wrapper</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
Next, I noticed that the Maven build does not seem to start the local (127.0.0.1) database because Spring Boot says this at start-up:
(...)
2018-01-02 17:57:18.882 INFO 14480 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2018-01-02 17:57:20.007 ERROR 14480 --- [tionPool-Create] com.alibaba.druid.pool.DruidDataSource : create connection error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590) ~[mysql-connector-java-6.0.6.jar:6.0.6]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57) ~[mysql-connector-java-6.0.6.jar:6.0.6]
(...)
Would you mind refactoring your GitHub project into an MCVE first before I can check on your actual problem? This way the error is not reproducible.
But having said this, I did notice something in your POM and Java files: Maybe the problem is not where you think it is. I can see that you want to use Lombok in combination with Spring AOP. According to my answer here, there are compatibility problems between AspectJ and Lombok. Maybe they also affect Spring AOP. So can you temporarily test without #Slf4j and other Lombok stuff? As soon as you will have fixed your project I can also test by myself.
Update after GitHub repo project has been repaired:
Now I can build and run your program, thanks. It seems that the parameter is somehow passed through to internal Spring classes you do not wish to target. So just modify your pointcut like this:
#After("#args(com.example.demosm.my.aop.NeedTestClass) && within(com.example.demosm..*)")

Can't run Geb tests using HtmlUnitDriver under Maven

I am running the example Google spec, i.e:
class GoogleHomePageSpec extends GebReportingSpec {
def "first result for wikipedia search should be wikipedia"() {
given:
to GoogleHomePage
expect:
at GoogleHomePage
when:
search.field.value("wikipedia")
then:
waitFor { at GoogleResultsPage }
and:
firstResultLink.text().startsWith "Wikipedia"
when:
firstResultLink.click()
then:
waitFor { at WikipediaPage }
}
}
with the following GebSpec:
reportsDir = "target/geb-reports"
/* webdriver.*.driver system properties are set in the POM */
driver = {
new HtmlUnitDriver();
}
and the following relevant pom.xml excerpt:
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>0.9.2</version>
<scope>test</scope>
</dependency>
and it fails with the message if I run it from CLI or IDE:
First result for wikipedia search should be wikipedia(scratch.GoogleHomePageSpec) Time elapsed: 0.96 sec <<< ERROR!
geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure1#20fcbdaf'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/set/ListOrderedSet
at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:59)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:131)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:289)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:144)
at GebConfig.run_closure1(GebConfig.groovy:10)
at GebConfig.run_closure1(GebConfig.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
I've checked and the commons-collection jar is present and contains the 'missing' class.
I don't get this error at all using ChromeDriver, FirefoxDriver and InternetExplorerDriver.
Unfortunately for environmental reasons I have to use HtmlUnitDriver so I'm really scratching my head about this one.
Would be grateful for any suggestions.
EDIT 1:
Have managed to run a portion of this test successfully on my Mac, the remainder times out.
But am not seeing the same errors as above (which were observed on Windows).
Resolved this problem by rebuilding the maven_repo i.e. moving the old one out of the way so maven is forced to rebuild it on the next run of the tests.
The exception no longer appears.

Where did the execute call go in BigQuery Requests?

I am following the Code lab here https://developers.google.com/bigquery/articles/gettingstartedwithjava to make requests to big query. One of the code samples here says:
Datasets.List datasetRequest = bigquery.datasets().list(projectId);
DatasetList datasetList = datasetRequest.execute();
But I am getting a "The method execute() is undefined for the type Bigquery.Datasets.List" error.
Any idea whats going on?
I am on version google-api-services-bigquery-v2-rev42-1.12.0-beta if that matters.
You need to explicitly add this dependency to get it working. The dependency in the pom for google-api-services-bigquery seem to be wrong. Which causes this exception.
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.12.0-beta</version>
</dependency>

EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available
import org.easymock.*;
import org.junit.*;
public class MyTest {
#Test
public void testWithClass() {
Thread threadMock = EasyMock.createMock(Thread.class);
EasyMock.expect(threadMock.isAlive()).andReturn(true);
}
}
I am not sure what I am doing wrong and can not find any good examples on the web. How do you mock a class using EasyMock 3.0. What is wrong with the above unit test? Any help would be greatly appreciated.
My project includes the following maven dependencies
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
The reason for this exception is that Thread#isAlive() is a final method, but EasyMock does not support the mocking of final methods. So, the call to this method which appears inside EasyMock.expect(...) is not seen as a "call on a mock".
To mock final methods you would need a different mocking tool, such as JMockit (which I develop):
public void testMockingFinalMethod(#Mocked("isAlive") Thread mock)
{
new Expectations()
{{
mock.isAlive(); result = true;
}};
assertTrue(mock.isAlive());
}
The mocking API doesn't actually require that methods to be mocked are specified explicitly, in the general case. The Thread class is a tricky one, though.
Your test method looks fine, except that you have not prepared the mock object you have created. This has to be done using
EasyMock.replay(mockObject1, mockObject2, ...);
This will prepare the mocked object so that it is the one which will be used on running your JUnit. No issues with your dependencies as well.
Also, you don't seem to be calling the actual method which you are unit-testing here. Usually, the way to write a test method would be to write a JUnit method, using mocking libs
(such as EasyMock and PowerMock) ONLY when there are external objects beyond the test method context, and then replaying all the mocked objects (which prepares the mocks to substitute for the real business objects in the test). After that, you call the actual method you are trying to test, and validate the functionality using org.junit.Assert.assertXXX() methods.
I had multiple calls to EasyMock.replay(mock) within one test case or suite causing this issue, and calling EasyMock.reset(mock) between each solved the problem.

Resources