-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review: Add more realistic shopping example application for onion arc…
…hitecture. Adjust integration test to match example. Issue: #174 Signed-off-by: Peter Gafert <[email protected]>
- Loading branch information
1 parent
5873ef6
commit daa45b9
Showing
29 changed files
with
394 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...in/java/com/tngtech/archunit/example/onionarchitecture/adapter/cli/AdministrationCLI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.cli; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.adapter.persistence.ProductRepository; | ||
import com.tngtech.archunit.example.onionarchitecture.application.AdministrationPort; | ||
import com.tngtech.archunit.example.onionarchitecture.application.ShoppingApplication; | ||
|
||
@SuppressWarnings("unused") | ||
public class AdministrationCLI { | ||
public static void main(String[] args) { | ||
AdministrationPort port = ShoppingApplication.openAdministrationPort(); | ||
handle(args, port); | ||
} | ||
|
||
private static void handle(String[] args, AdministrationPort port) { | ||
// violates the pairwise independence of adapters | ||
ProductRepository repository = port.getInstanceOf(ProductRepository.class); | ||
long count = repository.getTotalCount(); | ||
// parse arguments and re-configure application according to count through port | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
...java/com/tngtech/archunit/example/onionarchitecture/adapter/cli/CliAdapterLayerClass.java
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
.../archunit/example/onionarchitecture/adapter/persistence/PersistenceAdapterLayerClass.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
...in/java/com/tngtech/archunit/example/onionarchitecture/adapter/persistence/ProductId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import java.util.UUID; | ||
|
||
@SuppressWarnings("unused") | ||
public class ProductId { | ||
private final UUID id; | ||
|
||
public ProductId(UUID id) { | ||
if (id == null) { | ||
throw new IllegalArgumentException("ID must not be null"); | ||
} | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "{id=" + id + '}'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../tngtech/archunit/example/onionarchitecture/adapter/persistence/ProductJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.domain.model.Product; | ||
import com.tngtech.archunit.example.onionarchitecture.domain.service.ProductName; | ||
|
||
@SuppressWarnings("unused") | ||
public class ProductJpaRepository implements ProductRepository { | ||
@Override | ||
public Product read(ProductId id) { | ||
return new Product(id, new ProductName("would normally be read")); | ||
} | ||
|
||
@Override | ||
public long getTotalCount() { | ||
return 0; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...com/tngtech/archunit/example/onionarchitecture/adapter/persistence/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.domain.model.Product; | ||
|
||
// Violates the architecture because Domain must be the owner of the interfaces, not the persistence adapter | ||
public interface ProductRepository { | ||
Product read(ProductId id); | ||
|
||
long getTotalCount(); | ||
} |
19 changes: 19 additions & 0 deletions
19
...va/com/tngtech/archunit/example/onionarchitecture/adapter/persistence/ShoppingCartId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import java.util.UUID; | ||
|
||
public class ShoppingCartId { | ||
private final UUID id; | ||
|
||
public ShoppingCartId(UUID id) { | ||
if (id == null) { | ||
throw new IllegalArgumentException("ID must not be null"); | ||
} | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "{id=" + id + '}'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ech/archunit/example/onionarchitecture/adapter/persistence/ShoppingCartJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.domain.model.ShoppingCart; | ||
|
||
@SuppressWarnings("unused") | ||
public class ShoppingCartJpaRepository implements ShoppingCartRepository { | ||
@Override | ||
public ShoppingCart read(ShoppingCartId id) { | ||
// would normally load fully initialized shopping cart | ||
return new ShoppingCart(id); | ||
} | ||
|
||
@Override | ||
public void save(ShoppingCart shoppingCart) { | ||
// store shopping cart via JPA | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ngtech/archunit/example/onionarchitecture/adapter/persistence/ShoppingCartRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.persistence; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.domain.model.ShoppingCart; | ||
|
||
// Violates the architecture because Domain must be the owner of the interfaces, not the persistence adapter | ||
public interface ShoppingCartRepository { | ||
ShoppingCart read(ShoppingCartId id); | ||
|
||
void save(ShoppingCart shoppingCart); | ||
} |
28 changes: 0 additions & 28 deletions
28
...va/com/tngtech/archunit/example/onionarchitecture/adapter/rest/RestAdapterLayerClass.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
.../java/com/tngtech/archunit/example/onionarchitecture/adapter/rest/ShoppingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.adapter.rest; | ||
|
||
import java.util.UUID; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.adapter.persistence.ProductId; | ||
import com.tngtech.archunit.example.onionarchitecture.adapter.persistence.ShoppingCartId; | ||
import com.tngtech.archunit.example.onionarchitecture.domain.service.OrderQuantity; | ||
import com.tngtech.archunit.example.onionarchitecture.domain.service.ShoppingService; | ||
|
||
@SuppressWarnings("unused") | ||
public class ShoppingController { | ||
private final ShoppingService shoppingService; | ||
|
||
public ShoppingController(ShoppingService shoppingService) { | ||
this.shoppingService = shoppingService; | ||
} | ||
|
||
// @POST or similar | ||
public void addToShoppingCart(UUID shoppingCartId, UUID productId, int quantity) { | ||
shoppingService.addToShoppingCart(new ShoppingCartId(shoppingCartId), new ProductId(productId), new OrderQuantity(quantity)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...n/java/com/tngtech/archunit/example/onionarchitecture/application/AdministrationPort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.application; | ||
|
||
public interface AdministrationPort { | ||
<T> T getInstanceOf(Class<T> type); | ||
} |
28 changes: 0 additions & 28 deletions
28
...ava/com/tngtech/archunit/example/onionarchitecture/application/ApplicationLayerClass.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
.../java/com/tngtech/archunit/example/onionarchitecture/application/ShoppingApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.application; | ||
|
||
public class ShoppingApplication { | ||
public static void main(String[] args) { | ||
// start the whole application / provide IOC features | ||
} | ||
|
||
public static AdministrationPort openAdministrationPort() { | ||
return new AdministrationPort() { | ||
@Override | ||
public <T> T getInstanceOf(Class<T> type) { | ||
throw new UnsupportedOperationException("Not yet implemented"); | ||
} | ||
}; | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
...va/com/tngtech/archunit/example/onionarchitecture/domain/model/DomainModelLayerClass.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
.../src/main/java/com/tngtech/archunit/example/onionarchitecture/domain/model/OrderItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.domain.model; | ||
|
||
import com.tngtech.archunit.example.onionarchitecture.domain.service.OrderQuantity; | ||
|
||
public class OrderItem { | ||
private final Product product; | ||
private final OrderQuantity quantity; | ||
|
||
public OrderItem(Product product, OrderQuantity quantity) { | ||
if (product == null) { | ||
throw new IllegalArgumentException("Product must not be null"); | ||
} | ||
if (quantity == null) { | ||
throw new IllegalArgumentException("Quantity not be null"); | ||
} | ||
this.product = product; | ||
this.quantity = quantity; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "{product=" + product + ", quantity=" + quantity + '}'; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../main/java/com/tngtech/archunit/example/onionarchitecture/domain/model/PaymentMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tngtech.archunit.example.onionarchitecture.domain.model; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public class PaymentMethod { | ||
} |
Oops, something went wrong.