Skip to content

Commit

Permalink
refactor: add issue derjust#233 fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagocpeixoto committed Feb 25, 2019
1 parent 3cbd580 commit cfcf2fe
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.5</version>
<version>3.1.11</version>
<configuration>
<effort>Max</effort>
<!-- Reports all bugs (other values are medium and max) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package org.socialsignin.spring.data.dynamodb.repository.config;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate;
Expand All @@ -38,6 +34,11 @@
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author Michael Lavelle
* @author Sebastian Just
Expand Down Expand Up @@ -77,7 +78,7 @@ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfi

/*
* (non-Javadoc)
*
*
* @see org.springframework.data.repository.config.
* RepositoryConfigurationExtensionSupport
* #postProcess(org.springframework.beans
Expand All @@ -100,7 +101,6 @@ public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfiguratio
defaultDynamoDBMappingContext = registerDynamoDBMappingContext(registry);
}
dynamoDBMappingContextRef = defaultDynamoDBMappingContext;

}
registerAndSetPostProcessingBeans(builder, registry, dynamoDBMappingContextRef);
}
Expand Down Expand Up @@ -150,7 +150,6 @@ private void postProcess(BeanDefinitionBuilder builder, String repositoryName, S
defaultDynamoDBMappingContext = registerDynamoDBMappingContext(registry);
}
dynamoDBMappingContextRef = defaultDynamoDBMappingContext;

}

builder.addPropertyReference("dynamoDBMappingContext", dynamoDBMappingContextRef);
Expand Down Expand Up @@ -250,5 +249,4 @@ protected String getBeanNameWithModulePrefix(String baseBeanName) {
protected String getModulePrefix() {
return "dynamoDB";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.socialsignin.spring.data.dynamodb.repository.config;

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Test Issue #233 fix
*/
public class DynamoDBMapperConfigTest {

static class BaseTestConfig {
@Bean
public AmazonDynamoDB amazonDynamoDB() {
return Mockito.mock(AmazonDynamoDB.class);
}

@Bean
public DynamoDBMapper dynamoDBMapper() {
return Mockito.mock(DynamoDBMapper.class);
}
}

@Configuration
@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "customDynamoDBMapperConfig")
static class TestConfigWithDynamoDBMapperConfigRef extends BaseTestConfig {
@Bean("customDynamoDBMapperConfig")
public DynamoDBMapperConfig dynamoDBMapperConfig() {
return DynamoDBMapperConfig.DEFAULT;
}
}

@Configuration
@EnableDynamoDBRepositories
static class TestConfigWithoutDynamoDBMapperConfigRef extends TestConfigWithDynamoDBMapperConfigRef {
}

@Configuration
@EnableDynamoDBRepositories
static class TestConfigWithoutDynamoDBMapperConfigBean extends BaseTestConfig {
}

@Test
public void testConfigWithDynamoDBMapperConfigRef() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
TestConfigWithDynamoDBMapperConfigRef.class);

boolean containsBean = ctx.containsBean("customDynamoDBMapperConfig");
assertTrue(containsBean);
}

@Test(expected = UnsatisfiedDependencyException.class)
public void testConfigWithoutDynamoDBMapperConfigRef() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
TestConfigWithoutDynamoDBMapperConfigRef.class);

boolean containsBean = ctx.containsBean("customDynamoDBMapperConfig");
assertTrue(containsBean);
}

@Test
public void testConfigWithoutDynamoDBMapperConfigBean() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
TestConfigWithoutDynamoDBMapperConfigBean.class);

boolean containsBean = ctx.containsBean("customDynamoDBMapperConfig");
assertFalse(containsBean);

containsBean = ctx.containsBean("dynamoDB-DynamoDBMapperConfig");
assertTrue(containsBean);
}
}

0 comments on commit cfcf2fe

Please sign in to comment.