Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public abstract class AbstractSingleEntityQuery<T> extends AbstractQuery<T> implements Query<T> {

public AbstractSingleEntityQuery(DynamoDBOperations dynamoDBOperations,Class<T> clazz) {
public AbstractSingleEntityQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
super(dynamoDBOperations,clazz);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
*/
public class QueryExpressionCountQuery<T> extends AbstractSingleEntityQuery<Long> {

private DynamoDBQueryExpression<T> queryExpression;

private Class<T> domainClass;

private final DynamoDBQueryExpression<T> queryExpression;
private final Class<T> domainClass;

public QueryExpressionCountQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz,
DynamoDBQueryExpression<T> queryExpression) {
Expand All @@ -37,7 +35,7 @@ public QueryExpressionCountQuery(DynamoDBOperations dynamoDBOperations, Class<T>

@Override
public Long getSingleResult() {
return new Long(dynamoDBOperations.count(domainClass, queryExpression));
return Long.valueOf(dynamoDBOperations.count(domainClass, queryExpression));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;

public class QueryRequestCountQuery<T> extends AbstractSingleEntityQuery<Long> {
public class QueryRequestCountQuery extends AbstractSingleEntityQuery<Long> {

private DynamoDBOperations dynamoDBOperations;
private QueryRequest queryRequest;
private final DynamoDBOperations dynamoDBOperations;
private final QueryRequest queryRequest;

public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations,Class<T> clazz,QueryRequest queryRequest) {
public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations, QueryRequest queryRequest) {
super(null, Long.class);
this.queryRequest = queryRequest;
this.dynamoDBOperations = dynamoDBOperations;
Expand All @@ -32,7 +32,7 @@ public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations,Class<T> cla
@Override
public Long getSingleResult() {

return new Long(dynamoDBOperations.count(clazz, queryRequest));
return Long.valueOf(dynamoDBOperations.count(clazz, queryRequest));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperation
QueryRequest queryRequest = buildQueryRequest(tableName, getGlobalSecondaryIndexName(),
getHashKeyAttributeName(), getRangeKeyAttributeName(), this.getRangeKeyPropertyName(),
getHashKeyConditions(), getRangeKeyConditions());
return new QueryRequestCountQuery<T>(dynamoDBOperations,entityInformation.getJavaType(), queryRequest);
return new QueryRequestCountQuery(dynamoDBOperations, queryRequest);

} else {
DynamoDBQueryExpression<T> queryExpression = buildQueryExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperation
List<Condition> hashKeyConditions = getHashKeyConditions();
QueryRequest queryRequest = buildQueryRequest(dynamoDBOperations.getOverriddenTableName(clazz, entityInformation.getDynamoDBTableName()),
getGlobalSecondaryIndexName(), getHashKeyAttributeName(), null, null, hashKeyConditions, null);
return new QueryRequestCountQuery<>(dynamoDBOperations, entityInformation.getJavaType(), queryRequest);
return new QueryRequestCountQuery(dynamoDBOperations, queryRequest);

} else {
return new ScanExpressionCountQuery<>(dynamoDBOperations, clazz, buildScanExpression(),pageQuery);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright © 2013 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.query;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
import org.socialsignin.spring.data.dynamodb.domain.sample.User;

import java.util.List;
import java.util.Random;

import static org.junit.Assert.assertEquals;

public class AbstractSingleEntityQueryTest {

@Mock
private DynamoDBOperations dynamoDBOperations;
@Mock
private User entity;

private AbstractSingleEntityQuery<User> underTest;

@Before
public void setUp() {
underTest = new AbstractSingleEntityQuery<User>(dynamoDBOperations, User.class) {
@Override
public User getSingleResult() {
return entity;
}
};
}

@Test
public void testGetResultList() {
List<User> actual = underTest.getResultList();

assertEquals(1, actual.size());
assertEquals(entity, actual.get(0));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright © 2013 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.query;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
import org.socialsignin.spring.data.dynamodb.domain.sample.User;

import java.util.Random;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class QueryExpressionCountQueryTest {

private static final Random r = new Random();
@Mock
private DynamoDBOperations dynamoDBOperations;
@Mock
private DynamoDBQueryExpression<User> queryExpression;

private QueryExpressionCountQuery<User> underTest;

@Before
public void setUp() {
underTest = new QueryExpressionCountQuery(dynamoDBOperations, User.class, queryExpression);
}

@Test
public void testGetSingleResult() {
int expected = r.nextInt();
when(dynamoDBOperations.count(User.class, queryExpression)).thenReturn(expected);

Long actual = underTest.getSingleResult();

assertEquals(Long.valueOf(expected), actual);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright © 2013 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.query;

import com.amazonaws.services.dynamodbv2.model.QueryRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;

import java.util.Random;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class QueryRequestCountQueryTest {

private static final Random r = new Random();
@Mock
private DynamoDBOperations dynamoDBOperations;
@Mock
private QueryRequest queryRequest;

private QueryRequestCountQuery underTest;

@Before
public void setUp() {
underTest = new QueryRequestCountQuery(dynamoDBOperations, queryRequest);
}

@Test
public void testGetSingleResult() {
int expected = r.nextInt();
when(dynamoDBOperations.count(Long.class, queryRequest)).thenReturn(expected);

Long actual = underTest.getSingleResult();

assertEquals(Long.valueOf(expected), actual);
}
}