Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a DomainRegistry to access to domain objects (repository,factory, service, policy) #62

Merged
merged 1 commit into from
Oct 7, 2015
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
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<version>0.7.3</version>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-reflect</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry;

import javax.inject.Inject;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.seedstack.business.api.Service;
import org.seedstack.business.api.domain.DomainPolicy;
import org.seedstack.business.api.domain.DomainRegistry;
import org.seedstack.business.api.domain.Factory;
import org.seedstack.business.api.domain.Repository;
import org.seedstack.business.internal.registry.fixtures.domain.Client;
import org.seedstack.business.internal.registry.fixtures.domain.Composite;
import org.seedstack.business.internal.registry.fixtures.domain.Product;
import org.seedstack.business.internal.registry.fixtures.policy.PolicyQualifier;
import org.seedstack.business.internal.registry.fixtures.policy.RebatePolicy;
import org.seedstack.business.internal.registry.fixtures.policy.RebatePolicyInternalWithQualifier;
import org.seedstack.business.internal.registry.fixtures.service.MyService;
import org.seedstack.business.internal.registry.fixtures.service.MyServiceInternal;
import org.seedstack.business.internal.registry.fixtures.service.MyServiceInternalWithQualiferNamed;
import org.seedstack.business.internal.registry.fixtures.service.RebateService;
import org.seedstack.business.internal.registry.fixtures.service.RebateServiceInternal;
import org.seedstack.business.internal.registry.fixtures.service.RebateServiceInternalWithQualifierComposite;
import org.seedstack.business.internal.registry.fixtures.service.RebateServiceInternalWithQualifierNamed;
import org.seedstack.business.internal.registry.fixtures.service.ServiceQualifier;
import org.seedstack.business.internal.registry.repository.ClientRepository;
import org.seedstack.business.internal.registry.repository.JpaQualifier;
import org.seedstack.seed.core.api.TypeOf;
import org.seedstack.seed.it.SeedITRunner;


/**
* Integration test for {@link DomainRegistry}.
* @author thierry.bouvet@mpsa.com
*
*/
@RunWith(SeedITRunner.class)
public class DomainRegistyIT {

@Inject
DomainRegistry domainRegistry;

/**
* Test to get a {@link Service} from the {@link DomainRegistry}.
*/
@Test
public void testServiceBase() {
MyService service = this.domainRegistry.getService(MyService.class);
Assertions.assertThat(service).isInstanceOf(MyServiceInternal.class);
}

/**
* Test to get a {@link Service} from the {@link DomainRegistry}.
*/
@Test
public void testService() {
TypeOf<RebateService<Client>> type = new TypeOf<RebateService<Client>>(){};

RebateService<Client> service = this.domainRegistry.getService(type);
Assertions.assertThat(service).isInstanceOf(RebateServiceInternal.class);
}

/**
* Test to get a {@link Service} from the {@link DomainRegistry}.
*/
@Test
public void testServiceWithStringQualifierFromTypeOf() {
TypeOf<RebateService<Client>> type = new TypeOf<RebateService<Client>>(){};

RebateService<Client> service = this.domainRegistry.getService(type,"Dummy");
Assertions.assertThat(service).isInstanceOf(RebateServiceInternalWithQualifierNamed.class);
}

/**
* Test to get a {@link Service} from the {@link DomainRegistry}.
*/
@Test
public void testServiceWithStringQualifier() {
MyService service = this.domainRegistry.getService(MyService.class,"Dummy");
Assertions.assertThat(service).isInstanceOf(MyServiceInternalWithQualiferNamed.class);
}

/**
* Test to get a {@link Service} with a qualifier from the {@link DomainRegistry}.
*/
@Test
public void testServiceWithQualifierAndComposite() {
TypeOf<RebateService<Composite<Long>>> type = new TypeOf<RebateService<Composite<Long>>>(){};
RebateService<Composite<Long>> service = this.domainRegistry.getService(type,ServiceQualifier.class);
Assertions.assertThat(service).isInstanceOf(RebateServiceInternalWithQualifierComposite.class);

}

/**
* Test to get a {@link DomainPolicy} from the {@link DomainRegistry}.
*/
@Test
public void testPolicy() {
RebatePolicy policy = this.domainRegistry.getPolicy(RebatePolicy.class);
final int rebateExpected = 10;
Assertions.assertThat(policy.calculateRebate(new Product(),10000)).isEqualTo(rebateExpected);
}

/**
* Test to get a {@link DomainPolicy} with a qualifier from the {@link DomainRegistry}.
*/
@Test
public void testPolicyWithQualifier() {
RebatePolicy policy = this.domainRegistry.getPolicy(RebatePolicy.class,PolicyQualifier.class);
Assertions.assertThat(policy).isInstanceOf(RebatePolicyInternalWithQualifier.class);
}

/**
* Test to get a {@link Repository} from the {@link DomainRegistry}.
*/
@Test
public void testRepository() {
Repository<Client, Long> repository = this.domainRegistry.getRepository(Client.class, Long.class, JpaQualifier.class);
Assertions.assertThat(repository).isInstanceOf(ClientRepository.class);
}

/**
* Test to get a {@link Repository} from the {@link DomainRegistry}.
*/
@Test
public void testRepositoryFromTypeOf() {
TypeOf<Repository<Client, Long>> typeOf = new TypeOf<Repository<Client, Long>>(){};
Repository<Client, Long> repository = this.domainRegistry.getRepository(typeOf, JpaQualifier.class);
Assertions.assertThat(repository).isInstanceOf(ClientRepository.class);
}

/**
* Test to get a {@link Factory} from the {@link DomainRegistry}.
*/
@Test
public void testFactory() {
Factory<Client> factory = domainRegistry.getFactory(Client.class);
Assertions.assertThat(factory).isInstanceOf(Factory.class);
}

/**
* Test to get a {@link Factory} from the {@link DomainRegistry}.
*/
@Test
public void testFactoryFromTypeOf() {
TypeOf<Factory<Client>> typeOf = new TypeOf<Factory<Client>>(){};

Factory<Client> factory = domainRegistry.getFactory(typeOf);
Assertions.assertThat(factory).isInstanceOf(Factory.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.domain;

import org.seedstack.business.api.domain.BaseAggregateRoot;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
public class Client extends BaseAggregateRoot<Long>{

@Override
public Long getEntityId() {
return 1L;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.domain;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/public class Composite<T> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.domain;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/public class Product {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.policy;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.inject.Qualifier;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/@Documented
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface PolicyQualifier {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.policy;

import org.seedstack.business.api.domain.DomainPolicy;
import org.seedstack.business.internal.registry.fixtures.domain.Product;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
@DomainPolicy
public interface RebatePolicy {

public float calculateRebate(Product product, float quantity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.policy;

import org.seedstack.business.internal.registry.fixtures.domain.Product;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
public class RebatePolicyInternal implements RebatePolicy{

@Override
public float calculateRebate(Product product, float quantity) {
return quantity / 1000;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.policy;

import org.seedstack.business.internal.registry.fixtures.domain.Product;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
@PolicyQualifier
public class RebatePolicyInternalWithQualifier implements RebatePolicy{

@Override
public float calculateRebate(Product product, float quantity) {
return quantity / 10;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.service;

import org.seedstack.business.api.Service;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
@Service
public interface MyService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.business.internal.registry.fixtures.service;

/**
* Dummy class.
* @author thierry.bouvet@mpsa.com
*
*/
public class MyServiceInternal implements MyService {

}
Loading