Search in sources :

Example 1 with ConsumerToken

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);
}
Also used : ConsumerToken(com.ctrip.framework.apollo.openapi.entity.ConsumerToken) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 2 with 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;
}
Also used : Date(java.util.Date) ConsumerToken(com.ctrip.framework.apollo.openapi.entity.ConsumerToken)

Example 3 with 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);
}
Also used : ConsumerToken(com.ctrip.framework.apollo.openapi.entity.ConsumerToken)

Example 4 with 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());
}
Also used : Date(java.util.Date) ConsumerToken(com.ctrip.framework.apollo.openapi.entity.ConsumerToken) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Example 5 with ConsumerToken

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());
}
Also used : Consumer(com.ctrip.framework.apollo.openapi.entity.Consumer) Date(java.util.Date) ConsumerToken(com.ctrip.framework.apollo.openapi.entity.ConsumerToken) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

Aggregations

ConsumerToken (com.ctrip.framework.apollo.openapi.entity.ConsumerToken)6 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)4 Test (org.junit.Test)4 Date (java.util.Date)3 Consumer (com.ctrip.framework.apollo.openapi.entity.Consumer)1