I have created a GameTest Class for extending my Testclasses, but when I use them I get the following error:
com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx64.dll' for target: Windows 8.1, 64-bit
My Class:
public class GameTest {
// This is our "test" application
private static Application application;
// Before running any tests, initialize the application with the headless backend
#BeforeClass
public static void init() {
// Note that we don't need to implement any of the listener's methods
application = new HeadlessApplication(new ApplicationListener() {
#Override public void create() {}
#Override public void resize(int width, int height) {}
#Override public void render() {}
#Override public void pause() {}
#Override public void resume() {}
#Override public void dispose() {}
});
// Use Mockito to mock the OpenGL methods since we are running headlessly
Gdx.gl20 = Mockito.mock(GL20.class);
Gdx.gl = Gdx.gl20;
}
// After we are done, clean up the application
#AfterClass
public static void cleanUp() {
// Exit the application first
application.exit();
application = null;
}
}
Can someone help me in which direction I should solve the problem ?
You probably did not add the libgdx test dependencies to your "build.gradle" file.
Try adding these dependencies to the “core” section:
testCompile "junit:junit:4.12"
testCompile "org.mockito:mockito-core:2.2.29"
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
// box2d dependencies if necessary
testCompile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
Related
When you test your code, you send a message to rabbit-mq. How do you get the message back when the test is over?
public interface RabbitProducer {
String OUTPUT = "rabbitmq_producer_channel";
#Output(OUTPUT)
MessageChannel output();
}
public class SysGroupServiceImpl {
#Autowired
private RabbitProducer rabbitProducer;
#Override
public Result remove(Collection<? extends Serializable> idList) {
rabbitProducer.output().send(MessageBuilder.withPayload(idList)
.setHeader("x-delay", 5000)
.setHeader("MessageType", "GroupBatchDelete").build());
return Result.booleanResult(true);
}
}
#SpringBootTest
#Transactional
#Rollback
public class SysGroupServiceTest {
#Autowired
private SysGroupService sysGroupService;
#Test
void removeTest(){
sysGroupService.remove(Stream.of("1").collect(Collectors.toList()));
}
}
I use Spring Cloud Stream to be compatible with RabbitMQ, and all the relevant code is there.Is there a way to mock this out?I tried the following scheme, but due to X-dealy, I got this error:No exchange type x-delayed-message
<dependency>
<groupId>com.github.fridujo</groupId>
<artifactId>rabbitmq-mock</artifactId>
</dependency>
#Component
public class RabbitMqMock {
#Bean
public ConnectionFactory connectionFactory() {
return new CachingConnectionFactory(MockConnectionFactoryFactory.build());
}
}
I know little about mocks. Can mocks create an X-delay exchange?
I have camel route as below
public class IncomingBatchFileRoute extends RouteBuilder {
#Value(CCS_PROCESSING_INCOMING_DIRECTORY)
private String source;
#Override
public void configure() throws Exception {
from(sourceLocation)).autoStartup(false).to("encryptionEndPoint");
}
}
I need to write a JUNIT For above camel route and am new to it and created a structure as below
public class IncomingBatchFileRouteTest extends CamelTestSupport{
#Override
public RoutesBuilder createRouteBuilder() throws Exception {
return new IncomingBatchFileRoute();
}
#Test
public void sampleMockTest() {
}
}
Not sure how to complete it. Request you to help me on this
You need to mock your encryptionEndPoint and start your route with a producerTemplate
#Produce(uri = CCS_PROCESSING_INCOMING_DIRECTORY)
protected ProducerTemplate template;
#EndpointInject(uri = "encryptionEndPoint")
protected MockEndpoint resultEndpoint;
#Test
public void sampleMockTest() {
// GIVEN
this.resultEndpoint.expectedMessageCount(1);
// WHEN
this.template.sendBody("Hey");
// THEN
this.resultEndpoint.assertIsSatisfied();
}
I am learning OAUTH2 implementation
When i hit my client end http://localhost:8082/ui - REST end point for UI which will take me to the secure URI http://localhost:8082/secure after logging into the auth server http://localhost:8081/auth/login.
But it fails at http://localhost:8082/ui/login and give me error as
org.springframework.security.oauth2.client.resource.UserRedirectRequiredException: A redirect is required to get the users approval
My client configuration is
OauthConfig.java
#EnableOAuth2Sso
#Configuration
public class OauthConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
http.antMatcher("/**").
authorizeRequests().antMatchers("/","/login**").permitAll().anyRequest().authenticated();
/*http
.authorizeRequests().anyRequest().authenticated();*/
}
}
and webconfig.java
#SuppressWarnings("deprecation")
#EnableWebMvc
#Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
// TODO Auto-generated method stub
configurer.enable();
}
#Override
public void addViewControllers(ViewControllerRegistry registry) {
// TODO Auto-generated method stub
super.addViewControllers(registry);
registry.addViewController("/").setViewName("forward:/index");
registry.addViewController("/index");
registry.addViewController("/secure");
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
#Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer()
{
return new PropertySourcesPlaceholderConfigurer();
}
#Bean
public RequestContextListener contextlist()
{
return new RequestContextListener();
}
#Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
and my application.yml is
server:
port: 8082
servlet:
context-path: /ui
session:
cookieName: UISESSION
spring:
thymeleaf:
cache: false
oauth2:
client:
client-id: ClientId
clientSecret: secret
accessTokenUri: http://localhost:8081/auth/oauth/token
userAuthorizationUri: http://localhost:8081/auth/oauth/authorize
clientAuthenticationScheme: form
resource:
userInfoUri: http://localhost:8081/auth/rest/hello/principal
preferTokenInfo: false
Do i need to write custom oauth2ClientContextFilter for this? i already have added spring-security-oauth2 to the pom.xml. Any help would be really appreciated.
I had a similar experience and by exchanging #EnableOAuth2Sso by #EnableOAuth2Client it was solved.
It seems that the #EnableOAuth2Sso annotation adds an additional Security Chain Filter OAuth2ClientAuthenticationProcessingFilter to the springSecurityFilterChain and this throws the UserRedirectRequiredException.
Update SecurityContextHolder
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
Does anyone tuned spring boot to use as a view plain html without thymeleaf?
Here is my configuration:
#SpringBootApplication
#EnableAutoConfiguration
#ComponentScan
#Configuration
#EnableWebMvc
public class WebUi extends WebMvcConfigurerAdapter {
#Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}
#Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
//
// #Override
// public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
// configurer.enable();
// }
public static void main(String[] args) {
SpringApplication.run(WebUi.class, args);
}
}
I've tried with enabling DefaultServletHandler and without. The html file placed in src/main/resources/WEB-INF/login.html and assembled. I see it in the classpath in debug. But request to http://localhost:8080/login returns 404.
What I'm doing wrong?
Remove all annotations only leave #SpringBootApplication.
Remove your InternalResourceViewResolver and simply add the following to the application.properties.
spring.view.prefix=/WEB-INF/
spring.view.suffix=.html
Your current application class interferes with the Spring Boot auto configuration due to the #EnableWebMvc. Next #SpringBootApplication already implies #Configuration, #EnableAutoConfiguration and #ComponentScan no need to add them again.
When adding the spring.view.* properties Spring Boot already configures a InternalResourceViewResolver for you.
Basic advice here is work with the framework not around/against the framework.
I would like to be able for Mockito to perform a custom action when a given void method is called.
Say I have the following code:
#Autowired
private ProfileService profileService;
#Autowired
private ProfileDao profileDao;
private List<Profile> profiles;
#Before
public void setup() {
Mockito.when(profileDao.findAll()).thenReturn(profiles);
Mockito.when(profileDao.persist(any(Profile.class))).thenAddProfileToAboveList...
}
#Configuration
public static class testConfiguration {
#Bean
public ProfileDao ProfileDao() {
return mock(ProfileDao.class);
}
}
Say I want to add a Profile instance to the profiles list. Can Mockito do that? If so how?
Use Mockito.doAnswer.
doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
// make the changes you need here
}})
.when(mock).someMethod();