use of com.ctrip.framework.apollo.openapi.entity.ConsumerToken in project apollo by ctripcorp.
the class ConsumerServiceTest method testGenerateAndEnrichConsumerTokenWithConsumerNotFound.
@Test(expected = IllegalArgumentException.class)
public void testGenerateAndEnrichConsumerTokenWithConsumerNotFound() throws Exception {
long someConsumerIdNotExist = 1;
ConsumerToken consumerToken = new ConsumerToken();
consumerToken.setConsumerId(someConsumerIdNotExist);
consumerService.generateAndEnrichToken(null, consumerToken);
}
use of com.ctrip.framework.apollo.openapi.entity.ConsumerToken in project apollo by ctripcorp.
the class ConsumerService method generateConsumerToken.
private ConsumerToken generateConsumerToken(Consumer consumer, Date expires) {
long consumerId = consumer.getId();
String createdBy = userInfoHolder.getUser().getUserId();
Date createdTime = new Date();
ConsumerToken consumerToken = new ConsumerToken();
consumerToken.setConsumerId(consumerId);
consumerToken.setExpires(expires);
consumerToken.setDataChangeCreatedBy(createdBy);
consumerToken.setDataChangeCreatedTime(createdTime);
consumerToken.setDataChangeLastModifiedBy(createdBy);
consumerToken.setDataChangeLastModifiedTime(createdTime);
generateAndEnrichToken(consumer, consumerToken);
return consumerToken;
}
use of com.ctrip.framework.apollo.openapi.entity.ConsumerToken in project apollo by ctripcorp.
the class ConsumerService method generateAndSaveConsumerToken.
public ConsumerToken generateAndSaveConsumerToken(Consumer consumer, Date expires) {
Preconditions.checkArgument(consumer != null, "Consumer can not be null");
ConsumerToken consumerToken = generateConsumerToken(consumer, expires);
consumerToken.setId(0);
return consumerTokenRepository.save(consumerToken);
}
use of com.ctrip.framework.apollo.openapi.entity.ConsumerToken in project apollo by ctripcorp.
the class ConsumerServiceTest method testGetConsumerId.
@Test
public void testGetConsumerId() throws Exception {
String someToken = "someToken";
long someConsumerId = 1;
ConsumerToken someConsumerToken = new ConsumerToken();
someConsumerToken.setConsumerId(someConsumerId);
when(consumerTokenRepository.findTopByTokenAndExpiresAfter(eq(someToken), any(Date.class))).thenReturn(someConsumerToken);
assertEquals(someConsumerId, consumerService.getConsumerIdByToken(someToken).longValue());
}
use of com.ctrip.framework.apollo.openapi.entity.ConsumerToken in project apollo by ctripcorp.
the class ConsumerServiceTest method testGenerateAndEnrichConsumerToken.
@Test
public void testGenerateAndEnrichConsumerToken() throws Exception {
String someConsumerAppId = "someAppId";
long someConsumerId = 1;
String someToken = "someToken";
Date generationTime = new Date();
Consumer consumer = mock(Consumer.class);
when(consumerRepository.findById(someConsumerId)).thenReturn(Optional.of(consumer));
when(consumer.getAppId()).thenReturn(someConsumerAppId);
when(consumerService.generateToken(someConsumerAppId, generationTime, someTokenSalt)).thenReturn(someToken);
ConsumerToken consumerToken = new ConsumerToken();
consumerToken.setConsumerId(someConsumerId);
consumerToken.setDataChangeCreatedTime(generationTime);
consumerService.generateAndEnrichToken(consumer, consumerToken);
assertEquals(someToken, consumerToken.getToken());
}
Aggregations