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

#1: implement layer dependency violations #14

Open
wants to merge 23 commits into
base: violations/layer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.batch;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.dataaccess.TaskItemRepository;

public class L11ViolationBatchLayerDependsOnDataaccessLayer {
// Violation! Batch layer should not depend on dataaccess layer
@Inject
TaskItemRepository taskItemRepository;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.batch;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.service.TaskService;

public class L7ViolationBatchLayerDependsOnServiceLayer {
// Violation! Batch layer should not depend on service layer
@Inject
TaskService taskService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.devonfw.sample.archunit.batch;
// This demo class is provided to be erroneously depended on by:
// L5ViolationClientLayerDependsOnBatchLayer and L6ViolationServiceLayerDependsOnBatchLayer
public class SampleBatchClass {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.client;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.logic.TaskItemMapper;

public class L3ViolationClientLayerDependsOnLogicLayer {
// Violation! Client layer should not depend on logic layer
@Inject
TaskItemMapper taskItemMapper;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.client;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.dataaccess.TaskItemRepository;

public class L4ViolationClientLayerDependsOnDataaccessLayer {
// Violation! Client layer should not depend on dataaccess layer
@Inject
TaskItemRepository taskItemRepository;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.client;

import javax.inject.Inject;

import com.devonfw.sample.archunit.batch.SampleBatchClass;

public class L5ViolationClientLayerDependsOnBatchLayer {
// Violation! Client layer should not depend on batch layer
@Inject
SampleBatchClass sampleBatchClass;
}
28 changes: 28 additions & 0 deletions src/main/java/com/devonfw/sample/archunit/client/SampleClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.devonfw.sample.archunit.client;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

public class SampleClient {

public static void httpGetTaskItem(String taskId) throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.version(HttpClient.Version.HTTP_2)
.uri(URI.create("http://localhost:8080/task/item/" + taskId))
.headers("Accept-Enconding", "gzip, deflate")
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

String responseBody = response.body();
int responseStatusCode = response.statusCode();

System.out.println("httpGetRequest: " + responseBody);
System.out.println("httpGetRequest status code: " + responseStatusCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.devonfw.sample.archunit.task.common;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.logic.TaskItemMapper;

public class L1ViolationCommonLayerDependsOnOtherLayer {
@Inject
TaskItemMapper taskItemMapper;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.task.dataaccess;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.service.TaskService;

public class L10ViolationDataaccessLayerDependsOnServiceLayer {
// Violation! Dataaccess layer should not depend on service layer.
@Inject
TaskService taskService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.task.dataaccess;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.logic.TaskItemMapper;

public class L12ViolationDataaccessLayerDependsOnLogicLayer {
// Violation! Dataaccess layer should not depend on logic layer.
@Inject
TaskItemMapper taskItemMapper;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.devonfw.sample.archunit.task.logic;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.service.TaskService;

public class L9ViolationLogicLayerDependsOnServiceLayer {
// Violation! Logic layer should not depend on service layer
@Inject
TaskService taskService;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.task.service;

import javax.inject.Inject;

import com.devonfw.sample.archunit.client.SampleClient;

public class L2ViolationNoLayerOtherThanClientDependsOnClientLayer {
// Violation: service layer may not depend on client layer.
@Inject
SampleClient sampleClient;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.task.service;

import javax.inject.Inject;

import com.devonfw.sample.archunit.batch.SampleBatchClass;

public class L6ViolationServiceLayerDependsOnBatchLayer {
// Violation! Service layer should not depend on batch layer
@Inject
SampleBatchClass sampleBatchClass;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devonfw.sample.archunit.task.service;

import javax.inject.Inject;

import com.devonfw.sample.archunit.task.dataaccess.TaskItemRepository;

public class L8ViolationServiceLayerDependsOnDataaccessLayer {
// Violation! Service layer should not depend on dataaccess layer
@Inject
TaskItemRepository taskItemRepository;
}