use of com.ctrip.framework.apollo.openapi.entity.Consumer in project apollo by ctripcorp.
the class ConsumerService method createConsumer.
public Consumer createConsumer(Consumer consumer) {
String appId = consumer.getAppId();
Consumer managedConsumer = consumerRepository.findByAppId(appId);
if (managedConsumer != null) {
throw new BadRequestException("Consumer already exist");
}
String ownerName = consumer.getOwnerName();
UserInfo owner = userService.findByUserId(ownerName);
if (owner == null) {
throw new BadRequestException(String.format("User does not exist. UserId = %s", ownerName));
}
consumer.setOwnerEmail(owner.getEmail());
String operator = userInfoHolder.getUser().getUserId();
consumer.setDataChangeCreatedBy(operator);
consumer.setDataChangeLastModifiedBy(operator);
return consumerRepository.save(consumer);
}
use of com.ctrip.framework.apollo.openapi.entity.Consumer in project apollo by ctripcorp.
the class ConsumerServiceTest method testGetConsumerByConsumerId.
@Test
public void testGetConsumerByConsumerId() throws Exception {
long someConsumerId = 1;
Consumer someConsumer = mock(Consumer.class);
when(consumerRepository.findOne(someConsumerId)).thenReturn(someConsumer);
assertEquals(someConsumer, consumerService.getConsumerByConsumerId(someConsumerId));
verify(consumerRepository, times(1)).findOne(someConsumerId);
}
use of com.ctrip.framework.apollo.openapi.entity.Consumer in project apollo by ctripcorp.
the class ConsumerServiceTest method testCreateConsumer.
@Test
public void testCreateConsumer() {
Consumer consumer = createConsumer(testConsumerName, testAppId, testOwner);
UserInfo owner = createUser(testOwner);
when(consumerRepository.findByAppId(testAppId)).thenReturn(null);
when(userService.findByUserId(testOwner)).thenReturn(owner);
when(userInfoHolder.getUser()).thenReturn(owner);
consumerService.createConsumer(consumer);
verify(consumerRepository).save(consumer);
}
use of com.ctrip.framework.apollo.openapi.entity.Consumer 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.findOne(someConsumerId)).thenReturn(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());
}
use of com.ctrip.framework.apollo.openapi.entity.Consumer in project apollo by ctripcorp.
the class ConsumerServiceTest method createConsumer.
private Consumer createConsumer(String name, String appId, String ownerName) {
Consumer consumer = new Consumer();
consumer.setName(name);
consumer.setAppId(appId);
consumer.setOwnerName(ownerName);
return consumer;
}
Aggregations