lab2 done

This commit is contained in:
2025-10-10 19:23:10 +04:00
parent 3bf26f7c2d
commit 63fb0a92d7
103 changed files with 1781 additions and 924 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
.gradle/workspace-id.txt Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -20,13 +20,13 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
}
tasks.named('test') {
useJUnitPlatform()
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -3,17 +3,17 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - DemoApplicationTests</title>
<title>Test results - CustomerServiceIntegrationTest</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>DemoApplicationTests</h1>
<h1>CustomerServiceIntegrationTest</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt;
<a href="../packages/com.example.demo.html">com.example.demo</a> &gt; DemoApplicationTests</div>
<a href="../packages/com.example.service.html">com.example.service</a> &gt; CustomerServiceIntegrationTest</div>
<div id="summary">
<table>
<tr>
@@ -23,7 +23,7 @@
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">1</div>
<div class="counter">4</div>
<p>tests</p>
</div>
</td>
@@ -41,7 +41,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.383s</div>
<div class="counter">0.349s</div>
<p>duration</p>
</div>
</td>
@@ -81,8 +81,23 @@
</tr>
</thead>
<tr>
<td class="success">contextLoads()</td>
<td class="success">0.383s</td>
<td class="success">createTest()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">deleteTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">getTest_WhenCustomerNotExists_ShouldThrowException()</td>
<td class="success">0.344s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">updateTest()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
</table>
@@ -90,8 +105,8 @@
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>09:05:47.895 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.DemoApplicationTests]: DemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
09:05:47.937 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.DemoApplication for test class com.example.demo.DemoApplicationTests
<pre>19:23:02.926 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.service.CustomerServiceIntegrationTest]: CustomerServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
19:23:02.970 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.CustomerServiceIntegrationTest
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
@@ -102,10 +117,9 @@
:: Spring Boot :: (v3.5.5)
2025-09-13T09:05:48.075+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : Starting DemoApplicationTests using Java 21.0.3 with PID 56029 (started by floom in /Users/floom/demo)
2025-09-13T09:05:48.075+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : No active profile set, falling back to 1 default profile: &quot;default&quot;
2025-09-13T09:05:48.407+04:00 INFO 56029 --- [demo] [ Test worker] o.s.v.b.OptionalValidatorFactoryBean : Failed to set up a Bean Validation provider: jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2025-09-13T09:05:48.517+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : Started DemoApplicationTests in 0.531 seconds (process running for 0.945)
2025-10-10T19:23:03.112+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : Starting CustomerServiceIntegrationTest using Java 21.0.3 with PID 20384 (started by floom in /Users/floom/PIbd-21_Kudrinsky_O.S._IP-6)
2025-10-10T19:23:03.113+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : No active profile set, falling back to 1 default profile: &quot;default&quot;
2025-10-10T19:23:03.648+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : Started CustomerServiceIntegrationTest in 0.628 seconds (process running for 1.067)
</pre>
</span>
</div>
@@ -128,7 +142,7 @@ WARNING: Dynamic loading of agents will be disallowed by default in a future rel
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 13 сент. 2025г., 09:05:48</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
</div>
</div>
</body>

View File

@@ -0,0 +1,127 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - DeliveryServiceIntegrationTest</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>DeliveryServiceIntegrationTest</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt;
<a href="../packages/com.example.service.html">com.example.service</a> &gt; DeliveryServiceIntegrationTest</div>
<div id="summary">
<table>
<tr>
<td>
<div class="summaryGroup">
<table>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">5</div>
<p>tests</p>
</div>
</td>
<td>
<div class="infoBox" id="failures">
<div class="counter">0</div>
<p>failures</p>
</div>
</td>
<td>
<div class="infoBox" id="ignored">
<div class="counter">0</div>
<p>ignored</p>
</div>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.008s</div>
<p>duration</p>
</div>
</td>
</tr>
</table>
</div>
</td>
<td>
<div class="infoBox success" id="successRate">
<div class="percent">100%</div>
<p>successful</p>
</div>
</td>
</tr>
</table>
</div>
<div class="tab-container">
<ul class="tabLinks">
<li>
<a href="#">Tests</a>
</li>
<li>
<a href="#">Standard output</a>
</li>
</ul>
<div class="tab">
<h2>Tests</h2>
<table>
<thead>
<tr>
<th>Test</th>
<th>Duration</th>
<th>Result</th>
</tr>
</thead>
<tr>
<td class="success">createTest()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">deleteTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">findByTrackingNumberTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">getTest_WhenDeliveryNotExists_ShouldThrowException()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">updateTest()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
</table>
</div>
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>2025-10-10T19:23:04.005+04:00 INFO 20384 --- [demo] [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.DeliveryServiceIntegrationTest]: DeliveryServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2025-10-10T19:23:04.006+04:00 INFO 20384 --- [demo] [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.DeliveryServiceIntegrationTest
</pre>
</span>
</div>
</div>
<div id="footer">
<p>
<div>
<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,132 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - OrderServiceIntegrationTest</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>OrderServiceIntegrationTest</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt;
<a href="../packages/com.example.service.html">com.example.service</a> &gt; OrderServiceIntegrationTest</div>
<div id="summary">
<table>
<tr>
<td>
<div class="summaryGroup">
<table>
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">6</div>
<p>tests</p>
</div>
</td>
<td>
<div class="infoBox" id="failures">
<div class="counter">0</div>
<p>failures</p>
</div>
</td>
<td>
<div class="infoBox" id="ignored">
<div class="counter">0</div>
<p>ignored</p>
</div>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.007s</div>
<p>duration</p>
</div>
</td>
</tr>
</table>
</div>
</td>
<td>
<div class="infoBox success" id="successRate">
<div class="percent">100%</div>
<p>successful</p>
</div>
</td>
</tr>
</table>
</div>
<div class="tab-container">
<ul class="tabLinks">
<li>
<a href="#">Tests</a>
</li>
<li>
<a href="#">Standard output</a>
</li>
</ul>
<div class="tab">
<h2>Tests</h2>
<table>
<thead>
<tr>
<th>Test</th>
<th>Duration</th>
<th>Result</th>
</tr>
</thead>
<tr>
<td class="success">createTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">deleteTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">findByCustomerIdTest()</td>
<td class="success">0.002s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">findByStatusTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">getTest_WhenOrderNotExists_ShouldThrowException()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
<tr>
<td class="success">updateTest()</td>
<td class="success">0.001s</td>
<td class="success">passed</td>
</tr>
</table>
</div>
<div class="tab">
<h2>Standard output</h2>
<span class="code">
<pre>2025-10-10T19:23:04.016+04:00 INFO 20384 --- [demo] [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.OrderServiceIntegrationTest]: OrderServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2025-10-10T19:23:04.016+04:00 INFO 20384 --- [demo] [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.OrderServiceIntegrationTest
</pre>
</span>
</div>
</div>
<div id="footer">
<p>
<div>
<label class="hidden" id="label-for-line-wrapping-toggle" for="line-wrapping-toggle">Wrap lines
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
</div>
</div>
</body>
</html>

View File

@@ -20,7 +20,7 @@
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">1</div>
<div class="counter">15</div>
<p>tests</p>
</div>
</td>
@@ -38,7 +38,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.383s</div>
<div class="counter">0.364s</div>
<p>duration</p>
</div>
</td>
@@ -80,12 +80,12 @@
<tbody>
<tr>
<td class="success">
<a href="packages/com.example.demo.html">com.example.demo</a>
<a href="packages/com.example.service.html">com.example.service</a>
</td>
<td>1</td>
<td>15</td>
<td>0</td>
<td>0</td>
<td>0.383s</td>
<td>0.364s</td>
<td class="success">100%</td>
</tr>
</tbody>
@@ -107,12 +107,32 @@
<tbody>
<tr>
<td class="success">
<a href="classes/com.example.demo.DemoApplicationTests.html">com.example.demo.DemoApplicationTests</a>
<a href="classes/com.example.service.CustomerServiceIntegrationTest.html">com.example.service.CustomerServiceIntegrationTest</a>
</td>
<td>1</td>
<td>4</td>
<td>0</td>
<td>0</td>
<td>0.383s</td>
<td>0.349s</td>
<td class="success">100%</td>
</tr>
<tr>
<td class="success">
<a href="classes/com.example.service.DeliveryServiceIntegrationTest.html">com.example.service.DeliveryServiceIntegrationTest</a>
</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>0.008s</td>
<td class="success">100%</td>
</tr>
<tr>
<td class="success">
<a href="classes/com.example.service.OrderServiceIntegrationTest.html">com.example.service.OrderServiceIntegrationTest</a>
</td>
<td>6</td>
<td>0</td>
<td>0</td>
<td>0.007s</td>
<td class="success">100%</td>
</tr>
</tbody>
@@ -126,7 +146,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 13 сент. 2025г., 09:05:48</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
</div>
</div>
</body>

View File

@@ -3,16 +3,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>Test results - Package com.example.demo</title>
<title>Test results - Package com.example.service</title>
<link href="../css/base-style.css" rel="stylesheet" type="text/css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/report.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<h1>Package com.example.demo</h1>
<h1>Package com.example.service</h1>
<div class="breadcrumbs">
<a href="../index.html">all</a> &gt; com.example.demo</div>
<a href="../index.html">all</a> &gt; com.example.service</div>
<div id="summary">
<table>
<tr>
@@ -22,7 +22,7 @@
<tr>
<td>
<div class="infoBox" id="tests">
<div class="counter">1</div>
<div class="counter">15</div>
<p>tests</p>
</div>
</td>
@@ -40,7 +40,7 @@
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.383s</div>
<div class="counter">0.364s</div>
<p>duration</p>
</div>
</td>
@@ -78,12 +78,32 @@
</thead>
<tr>
<td class="success">
<a href="../classes/com.example.demo.DemoApplicationTests.html">DemoApplicationTests</a>
<a href="../classes/com.example.service.CustomerServiceIntegrationTest.html">CustomerServiceIntegrationTest</a>
</td>
<td>1</td>
<td>4</td>
<td>0</td>
<td>0</td>
<td>0.383s</td>
<td>0.349s</td>
<td class="success">100%</td>
</tr>
<tr>
<td class="success">
<a href="../classes/com.example.service.DeliveryServiceIntegrationTest.html">DeliveryServiceIntegrationTest</a>
</td>
<td>5</td>
<td>0</td>
<td>0</td>
<td>0.008s</td>
<td class="success">100%</td>
</tr>
<tr>
<td class="success">
<a href="../classes/com.example.service.OrderServiceIntegrationTest.html">OrderServiceIntegrationTest</a>
</td>
<td>6</td>
<td>0</td>
<td>0</td>
<td>0.007s</td>
<td class="success">100%</td>
</tr>
</table>
@@ -96,7 +116,7 @@
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 13 сент. 2025г., 09:05:48</p>
<a href="https://www.gradle.org">Gradle 8.14.3</a> at 10 окт. 2025г., 19:23:04</p>
</div>
</div>
</body>

View File

@@ -1 +0,0 @@
com.example.controller.DemoApplication

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.demo.DemoApplicationTests" tests="1" skipped="0" failures="0" errors="0" timestamp="2025-09-13T05:05:48.521Z" hostname="MacBook-Air-Oleg.local" time="0.383">
<properties/>
<testcase name="contextLoads()" classname="com.example.demo.DemoApplicationTests" time="0.383"/>
<system-out><![CDATA[09:05:47.895 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.demo.DemoApplicationTests]: DemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
09:05:47.937 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.demo.DemoApplication for test class com.example.demo.DemoApplicationTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.5.5)
2025-09-13T09:05:48.075+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : Starting DemoApplicationTests using Java 21.0.3 with PID 56029 (started by floom in /Users/floom/demo)
2025-09-13T09:05:48.075+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : No active profile set, falling back to 1 default profile: "default"
2025-09-13T09:05:48.407+04:00 INFO 56029 --- [demo] [ Test worker] o.s.v.b.OptionalValidatorFactoryBean : Failed to set up a Bean Validation provider: jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2025-09-13T09:05:48.517+04:00 INFO 56029 --- [demo] [ Test worker] com.example.demo.DemoApplicationTests : Started DemoApplicationTests in 0.531 seconds (process running for 0.945)
]]></system-out>
<system-err><![CDATA[Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3
WARNING: A Java agent has been loaded dynamically (/Users/floom/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.17.7/fbf3d6d649ed37fc9e9c59480a05be0a26e3c2da/byte-buddy-agent-1.17.7.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
]]></system-err>
</testsuite>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.CustomerServiceIntegrationTest" tests="4" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:03.652Z" hostname="MacBook-Air-Oleg.local" time="0.35">
<properties/>
<testcase name="getTest_WhenCustomerNotExists_ShouldThrowException()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.344"/>
<testcase name="updateTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.002"/>
<testcase name="createTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.002"/>
<testcase name="deleteTest()" classname="com.example.service.CustomerServiceIntegrationTest" time="0.001"/>
<system-out><![CDATA[19:23:02.926 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.example.service.CustomerServiceIntegrationTest]: CustomerServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
19:23:02.970 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.CustomerServiceIntegrationTest
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.5.5)
2025-10-10T19:23:03.112+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : Starting CustomerServiceIntegrationTest using Java 21.0.3 with PID 20384 (started by floom in /Users/floom/PIbd-21_Kudrinsky_O.S._IP-6)
2025-10-10T19:23:03.113+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : No active profile set, falling back to 1 default profile: "default"
2025-10-10T19:23:03.648+04:00 INFO 20384 --- [demo] [ Test worker] c.e.s.CustomerServiceIntegrationTest : Started CustomerServiceIntegrationTest in 0.628 seconds (process running for 1.067)
]]></system-out>
<system-err><![CDATA[Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3
WARNING: A Java agent has been loaded dynamically (/Users/floom/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.17.7/fbf3d6d649ed37fc9e9c59480a05be0a26e3c2da/byte-buddy-agent-1.17.7.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
]]></system-err>
</testsuite>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.DeliveryServiceIntegrationTest" tests="5" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:04.006Z" hostname="MacBook-Air-Oleg.local" time="0.008">
<properties/>
<testcase name="updateTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<testcase name="findByTrackingNumberTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<testcase name="createTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<testcase name="deleteTest()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.001"/>
<testcase name="getTest_WhenDeliveryNotExists_ShouldThrowException()" classname="com.example.service.DeliveryServiceIntegrationTest" time="0.002"/>
<system-out><![CDATA[2025-10-10T19:23:04.005+04:00 INFO 20384 --- [demo] [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.DeliveryServiceIntegrationTest]: DeliveryServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2025-10-10T19:23:04.006+04:00 INFO 20384 --- [demo] [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.DeliveryServiceIntegrationTest
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="com.example.service.OrderServiceIntegrationTest" tests="6" skipped="0" failures="0" errors="0" timestamp="2025-10-10T15:23:04.017Z" hostname="MacBook-Air-Oleg.local" time="0.009">
<properties/>
<testcase name="findByStatusTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="updateTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="getTest_WhenOrderNotExists_ShouldThrowException()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="createTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<testcase name="findByCustomerIdTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.002"/>
<testcase name="deleteTest()" classname="com.example.service.OrderServiceIntegrationTest" time="0.001"/>
<system-out><![CDATA[2025-10-10T19:23:04.016+04:00 INFO 20384 --- [demo] [ Test worker] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.example.service.OrderServiceIntegrationTest]: OrderServiceIntegrationTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2025-10-10T19:23:04.016+04:00 INFO 20384 --- [demo] [ Test worker] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.example.DemoApplication for test class com.example.service.OrderServiceIntegrationTest
]]></system-out>
<system-err><![CDATA[]]></system-err>
</testsuite>

View File

@@ -1,12 +0,0 @@
Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.launch.JarLauncher
Start-Class: com.example.demo.DemoApplication
Spring-Boot-Version: 3.5.5
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
Build-Jdk-Spec: 21
Implementation-Title: demo
Implementation-Version: 0.0.1-SNAPSHOT

View File

@@ -1,2 +0,0 @@
Manifest-Version: 1.0

View File

@@ -25,10 +25,6 @@ function OrderList() {
fetch('http://localhost:8080/api/deliveries')
]);
if (!ordersRes.ok) throw new Error('Ошибка загрузки заказов');
if (!customersRes.ok) throw new Error('Ошибка загрузки клиентов');
if (!deliveriesRes.ok) throw new Error('Ошибка загрузки доставок');
const ordersData = await ordersRes.json();
const customersData = await customersRes.json();
const deliveriesData = await deliveriesRes.json();
@@ -66,17 +62,10 @@ function OrderList() {
const handleCreateOrder = async (orderData) => {
try {
const customer = customers.find(c => c.id === orderData.customerId);
const delivery = deliveries.find(d => d.id === orderData.deliveryId);
if (!customer || !delivery) {
alert('Ошибка: клиент или доставка не найдены');
return;
}
const newOrder = {
customer: customer,
delivery: delivery,
// Теперь отправляем OrderRq DTO с customerId и deliveryId
const orderRq = {
customerId: orderData.customerId,
deliveryId: orderData.deliveryId,
status: orderData.status
};
@@ -86,16 +75,14 @@ function OrderList() {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(newOrder)
body: JSON.stringify(orderRq)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
const errorText = await response.text();
throw new Error(errorText || `HTTP error! status: ${response.status}`);
}
const createdOrder = await response.json();
console.log('Создан заказ:', createdOrder);
await loadData();
setEditingOrder(null);
} catch (error) {
@@ -104,6 +91,36 @@ function OrderList() {
}
};
const handleUpdateOrder = async (orderData) => {
try {
const orderRq = {
customerId: orderData.customerId,
deliveryId: orderData.deliveryId,
status: orderData.status
};
const response = await fetch(`http://localhost:8080/api/orders/${editingOrder.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(orderRq)
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(errorText || `HTTP error! status: ${response.status}`);
}
await loadData();
setEditingOrder(null);
} catch (error) {
console.error('Ошибка обновления заказа:', error);
alert('Ошибка при обновлении заказа: ' + error.message);
}
};
const handleDeleteOrder = async (orderId) => {
if (window.confirm('Удалить этот заказ?')) {
try {
@@ -123,20 +140,28 @@ function OrderList() {
}
};
const handleFormSubmit = (orderData) => {
if (editingOrder) {
handleUpdateOrder(orderData);
} else {
handleCreateOrder(orderData);
}
};
if (loading) {
return <div>Загрузка...</div>;
}
return (
<div style={{ maxWidth: '1200px', margin: '0 auto' }}>
<h2>Управление заказами</h2>
<h2>📦 Управление заказами</h2>
<OrderStats orders={orders} />
<OrderForm
customers={customers}
deliveries={deliveries}
onSubmit={handleCreateOrder}
onSubmit={handleFormSubmit}
editOrder={editingOrder}
/>

View File

@@ -1,4 +1,4 @@
package com.example.controller;
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -6,8 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

View File

@@ -1,11 +1,14 @@
package com.example.controller;
import com.example.dto.CustomerDTO;
import com.example.dto.CustomerRq;
import com.example.dto.CustomerRs;
import com.example.service.CustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -15,48 +18,44 @@ import java.util.Optional;
@Tag(name = "Customer API", description = "Операции с клиентами")
public class CustomerController {
private final List<CustomerDTO> customers = new ArrayList<>();
private final CustomerService customerService;
public CustomerController() {
customers.add(new CustomerDTO("c1", "Иванов Иван", "ivanov@example.com"));
customers.add(new CustomerDTO("c2", "Петров Петр", "petrov@example.com"));
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
@GetMapping
@Operation(summary = "Получить всех клиентов")
public List<CustomerDTO> getAll() {
return customers;
public List<CustomerRs> getAll() {
return customerService.findAll();
}
@GetMapping("/{id}")
@Operation(summary = "Получить клиента по ID")
public CustomerDTO getOne(@PathVariable String id) {
return customers.stream().filter(c -> c.getId().equals(id)).findFirst().orElse(null);
public ResponseEntity<CustomerRs> getOne(@PathVariable String id) {
Optional<CustomerRs> customer = customerService.findById(id);
return customer.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
@Operation(summary = "Создать нового клиента")
public CustomerDTO create(@RequestBody CustomerDTO customer) {
customers.add(customer);
return customer;
public CustomerRs create(@Valid @RequestBody CustomerRq customerRq) {
return customerService.create(customerRq);
}
@PutMapping("/{id}")
@Operation(summary = "Обновить данные клиента")
public CustomerDTO update(@PathVariable String id, @RequestBody CustomerDTO updated) {
Optional<CustomerDTO> existing = customers.stream().filter(c -> c.getId().equals(id)).findFirst();
if (existing.isPresent()) {
CustomerDTO c = existing.get();
c.setName(updated.getName());
c.setEmail(updated.getEmail());
return c;
}
return null;
public ResponseEntity<CustomerRs> update(@PathVariable String id, @Valid @RequestBody CustomerRq customerRq) {
Optional<CustomerRs> updated = customerService.update(id, customerRq);
return updated.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
@Operation(summary = "Удалить клиента")
public void delete(@PathVariable String id) {
customers.removeIf(c -> c.getId().equals(id));
public ResponseEntity<Void> delete(@PathVariable String id) {
boolean deleted = customerService.delete(id);
return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
}
}

View File

@@ -1,13 +1,16 @@
package com.example.controller;
import com.example.dto.DeliveryDTO;
import com.example.dto.DeliveryRq;
import com.example.dto.DeliveryRs;
import com.example.service.DeliveryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
@CrossOrigin(origins = "http://localhost:5173")
@RestController
@@ -15,54 +18,44 @@ import java.util.UUID;
@Tag(name = "Delivery API", description = "Операции с доставками")
public class DeliveryController {
private final List<DeliveryDTO> deliveries = new ArrayList<>();
private final DeliveryService deliveryService;
public DeliveryController() {
deliveries.add(new DeliveryDTO("578a","IVN012021","гоголя10","Доставлено","Парт петрович wwww"));
deliveries.add(new DeliveryDTO("0e0f","IVN123456","Москва","В пути","1Иванов Иван"));
public DeliveryController(DeliveryService deliveryService) {
this.deliveryService = deliveryService;
}
@GetMapping
@Operation(summary = "Получить все доставки")
public List<DeliveryDTO> getAll() {
return deliveries;
public List<DeliveryRs> getAll() {
return deliveryService.findAll();
}
@GetMapping("/{id}")
@Operation(summary = "Получить доставку по ID")
public DeliveryDTO getOne(@PathVariable String id) {
return deliveries.stream()
.filter(d -> d.getId().equals(id))
.findFirst()
.orElseThrow(() -> new RuntimeException("Delivery not found"));
public ResponseEntity<DeliveryRs> getOne(@PathVariable String id) {
Optional<DeliveryRs> delivery = deliveryService.findById(id);
return delivery.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
@Operation(summary = "Создать новую доставку")
public DeliveryDTO create(@RequestBody DeliveryDTO delivery) {
if (delivery.getId() == null || delivery.getId().isEmpty()) {
delivery.setId(UUID.randomUUID().toString());
}
deliveries.add(delivery);
return delivery;
public DeliveryRs create(@Valid @RequestBody DeliveryRq deliveryRq) {
return deliveryService.create(deliveryRq);
}
@PutMapping("/{id}")
@Operation(summary = "Обновить данные доставки")
public DeliveryDTO update(@PathVariable String id, @RequestBody DeliveryDTO updated) {
for (int i = 0; i < deliveries.size(); i++) {
if (deliveries.get(i).getId().equals(id)) {
updated.setId(id);
deliveries.set(i, updated);
return updated;
}
}
throw new RuntimeException("Delivery not found");
public ResponseEntity<DeliveryRs> update(@PathVariable String id, @Valid @RequestBody DeliveryRq deliveryRq) {
Optional<DeliveryRs> updated = deliveryService.update(id, deliveryRq);
return updated.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
@Operation(summary = "Удалить доставку")
public void delete(@PathVariable String id) {
deliveries.removeIf(d -> d.getId().equals(id));
public ResponseEntity<Void> delete(@PathVariable String id) {
boolean deleted = deliveryService.delete(id);
return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
}
}

View File

@@ -1,105 +1,82 @@
package com.example.controller;
import com.example.dto.OrderDTO;
import com.example.dto.CustomerDTO;
import com.example.dto.DeliveryDTO;
import com.example.dto.OrderRq;
import com.example.dto.OrderRs;
import com.example.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RestController
@RequestMapping("/api/orders")
@Tag(name = "Order API", description = "Операции с заказами")
public class OrderController {
private final List<OrderDTO> orders = new ArrayList<>();
private final CustomerController customerController;
private final DeliveryController deliveryController;
private final OrderService orderService;
public OrderController(CustomerController customerController, DeliveryController deliveryController) {
this.customerController = customerController;
this.deliveryController = deliveryController;
initializeTestData();
}
private void initializeTestData() {
CustomerDTO customer1 = new CustomerDTO("c1", "Иванов Иван", "ivanov@example.com");
CustomerDTO customer2 = new CustomerDTO("c2", "Петров Петр", "petrov@example.com");
DeliveryDTO delivery1 = new DeliveryDTO("578a", "IVN012021", "гоголя10", "Доставлено", "Парт петрович wwww");
DeliveryDTO delivery2 = new DeliveryDTO("0e0f", "IVN123456", "Москва", "В пути", "1Иванов Иван");
orders.add(new OrderDTO("o1", customer1, delivery1, "Доставлено"));
orders.add(new OrderDTO("o2", customer2, delivery2, "В пути"));
public OrderController(OrderService orderService) {
this.orderService = orderService;
}
@GetMapping
@Operation(summary = "Получить все заказы")
public List<OrderDTO> getAll() {
return orders;
public List<OrderRs> getAll() {
return orderService.findAll();
}
@GetMapping("/{id}")
@Operation(summary = "Получить заказ по ID")
public OrderDTO getOne(@PathVariable String id) {
return orders.stream()
.filter(o -> o.getId().equals(id))
.findFirst()
.orElse(null);
public ResponseEntity<OrderRs> getOne(@PathVariable String id) {
Optional<OrderRs> order = orderService.findById(id);
return order.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@GetMapping("/customer/{customerId}")
@Operation(summary = "Получить заказы по ID клиента")
public List<OrderRs> getByCustomer(@PathVariable String customerId) {
return orderService.findByCustomerId(customerId);
}
@GetMapping("/status/{status}")
@Operation(summary = "Получить заказы по статусу")
public List<OrderDTO> getOrdersByStatus(@PathVariable String status) {
return orders.stream()
.filter(o -> o.getStatus().equalsIgnoreCase(status))
.toList();
}
@GetMapping("/sorted/by-status")
@Operation(summary = "Получить заказы отсортированные по статусу")
public List<OrderDTO> getOrdersSortedByStatus() {
return orders.stream()
.sorted(Comparator.comparing(OrderDTO::getStatus))
.toList();
public List<OrderRs> getByStatus(@PathVariable String status) {
return orderService.findByStatus(status);
}
@PostMapping
@Operation(summary = "Создать новый заказ")
public OrderDTO create(@RequestBody OrderDTO order) {
if (order.getId() == null || order.getId().isEmpty()) {
order.setId("order_" + System.currentTimeMillis());
public ResponseEntity<?> create(@Valid @RequestBody OrderRq orderRq) {
try {
OrderRs created = orderService.create(orderRq);
return ResponseEntity.ok(created);
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
orders.add(order);
return order;
}
@PutMapping("/{id}")
@Operation(summary = "Обновить заказ")
public OrderDTO update(@PathVariable String id, @RequestBody OrderDTO updatedOrder) {
Optional<OrderDTO> existing = orders.stream()
.filter(o -> o.getId().equals(id))
.findFirst();
if (existing.isPresent()) {
OrderDTO order = existing.get();
order.setCustomer(updatedOrder.getCustomer());
order.setDelivery(updatedOrder.getDelivery());
order.setStatus(updatedOrder.getStatus());
return order;
public ResponseEntity<?> update(@PathVariable String id, @Valid @RequestBody OrderRq orderRq) {
try {
Optional<OrderRs> updated = orderService.update(id, orderRq);
return updated.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
return null;
}
@DeleteMapping("/{id}")
@Operation(summary = "Удалить заказ")
public void delete(@PathVariable String id) {
orders.removeIf(o -> o.getId().equals(id));
public ResponseEntity<Void> delete(@PathVariable String id) {
boolean deleted = orderService.delete(id);
return deleted ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
}
}

View File

@@ -0,0 +1,28 @@
package com.example.dto;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
public class CustomerRq {
@NotBlank(message = "Имя обязательно")
private String name;
@NotBlank(message = "Email обязателен")
@Email(message = "Некорректный формат email")
private String email;
// Конструкторы
public CustomerRq() {}
public CustomerRq(String name, String email) {
this.name = name;
this.email = email;
}
// Геттеры и сеттеры
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
}

View File

@@ -0,0 +1,16 @@
package com.example.dto;
public class CustomerRs {
private String id;
private String name;
private String email;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
}

View File

@@ -0,0 +1,37 @@
package com.example.dto;
import jakarta.validation.constraints.NotBlank;
public class DeliveryRq {
@NotBlank(message = "Трек номер обязателен")
private String trackingNumber;
@NotBlank(message = "Адрес назначения обязателен")
private String destination;
@NotBlank(message = "Статус обязателен")
private String status;
private String customer;
public String getTrackingNumber() { return trackingNumber; }
public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; }
public String getDestination() { return destination; }
public void setDestination(String destination) { this.destination = destination; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public String getCustomer() { return customer; }
public void setCustomer(String customer) { this.customer = customer; }
public DeliveryRq() {}
public DeliveryRq(String trackingNumber, String destination, String status, String customer) {
this.trackingNumber = trackingNumber;
this.destination = destination;
this.status = status;
this.customer = customer;
}
}

View File

@@ -0,0 +1,24 @@
package com.example.dto;
public class DeliveryRs {
private String id;
private String trackingNumber;
private String destination;
private String status;
private String customer;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getTrackingNumber() { return trackingNumber; }
public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; }
public String getDestination() { return destination; }
public void setDestination(String destination) { this.destination = destination; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public String getCustomer() { return customer; }
public void setCustomer(String customer) { this.customer = customer; }
}

View File

@@ -0,0 +1,32 @@
package com.example.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
public class OrderRq {
@NotBlank(message = "ID клиента обязателен")
private String customerId;
@NotBlank(message = "ID доставки обязателен")
private String deliveryId;
@NotBlank(message = "Статус обязателен")
private String status;
public String getCustomerId() { return customerId; }
public void setCustomerId(String customerId) { this.customerId = customerId; }
public String getDeliveryId() { return deliveryId; }
public void setDeliveryId(String deliveryId) { this.deliveryId = deliveryId; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public OrderRq() {}
public OrderRq(String customerId, String deliveryId, String status) {
this.customerId = customerId;
this.deliveryId = deliveryId;
this.status = status;
}
}

View File

@@ -0,0 +1,21 @@
package com.example.dto;
public class OrderRs {
private String id;
private CustomerRs customer;
private DeliveryRs delivery;
private String status;
// Геттеры и сеттеры
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public CustomerRs getCustomer() { return customer; }
public void setCustomer(CustomerRs customer) { this.customer = customer; }
public DeliveryRs getDelivery() { return delivery; }
public void setDelivery(DeliveryRs delivery) { this.delivery = delivery; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
}

View File

@@ -0,0 +1,8 @@
package com.example.entity;
public abstract class BaseEntity {
protected String id;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
}

View File

@@ -0,0 +1,27 @@
package com.example.entity;
import java.util.ArrayList;
import java.util.List;
public class Customer extends BaseEntity {
private String name;
private String email;
private List<Order> orders = new ArrayList<>();
public Customer() {}
public Customer(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public List<Order> getOrders() { return orders; }
public void setOrders(List<Order> orders) { this.orders = orders; }
public void addOrder(Order order) { this.orders.add(order); }
}

View File

@@ -0,0 +1,29 @@
package com.example.entity;
public class Delivery extends BaseEntity {
private String trackingNumber;
private String destination;
private String status;
private String customer;
public Delivery() {}
public Delivery(String trackingNumber, String destination, String status, String customer) {
this.trackingNumber = trackingNumber;
this.destination = destination;
this.status = status;
this.customer = customer;
}
public String getTrackingNumber() { return trackingNumber; }
public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; }
public String getDestination() { return destination; }
public void setDestination(String destination) { this.destination = destination; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public String getCustomer() { return customer; }
public void setCustomer(String customer) { this.customer = customer; }
}

View File

@@ -0,0 +1,25 @@
package com.example.entity;
public class Order extends BaseEntity {
private Customer customer;
private Delivery delivery;
private String status;
// Конструкторы
public Order() {}
public Order(Customer customer, Delivery delivery, String status) {
this.customer = customer;
this.delivery = delivery;
this.status = status;
}
public Customer getCustomer() { return customer; }
public void setCustomer(Customer customer) { this.customer = customer; }
public Delivery getDelivery() { return delivery; }
public void setDelivery(Delivery delivery) { this.delivery = delivery; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
}

View File

@@ -0,0 +1,25 @@
package com.example.mapper;
import com.example.entity.Customer;
import com.example.dto.CustomerRq;
import com.example.dto.CustomerRs;
import org.springframework.stereotype.Component;
@Component
public class CustomerMapper {
public Customer toEntity(CustomerRq customerRq) {
Customer customer = new Customer();
customer.setName(customerRq.getName());
customer.setEmail(customerRq.getEmail());
return customer;
}
public CustomerRs toResponse(Customer customer) {
CustomerRs customerRs = new CustomerRs();
customerRs.setId(customer.getId());
customerRs.setName(customer.getName());
customerRs.setEmail(customer.getEmail());
return customerRs;
}
}

View File

@@ -0,0 +1,29 @@
package com.example.mapper;
import com.example.entity.Delivery;
import com.example.dto.DeliveryRq;
import com.example.dto.DeliveryRs;
import org.springframework.stereotype.Component;
@Component
public class DeliveryMapper {
public Delivery toEntity(DeliveryRq deliveryRq) {
Delivery delivery = new Delivery();
delivery.setTrackingNumber(deliveryRq.getTrackingNumber());
delivery.setDestination(deliveryRq.getDestination());
delivery.setStatus(deliveryRq.getStatus());
delivery.setCustomer(deliveryRq.getCustomer());
return delivery;
}
public DeliveryRs toResponse(Delivery delivery) {
DeliveryRs deliveryRs = new DeliveryRs();
deliveryRs.setId(delivery.getId());
deliveryRs.setTrackingNumber(delivery.getTrackingNumber());
deliveryRs.setDestination(delivery.getDestination());
deliveryRs.setStatus(delivery.getStatus());
deliveryRs.setCustomer(delivery.getCustomer());
return deliveryRs;
}
}

View File

@@ -0,0 +1,61 @@
package com.example.mapper;
import com.example.entity.Order;
import com.example.entity.Customer;
import com.example.entity.Delivery;
import com.example.dto.OrderRq;
import com.example.dto.OrderRs;
import com.example.dto.CustomerRs;
import com.example.dto.DeliveryRs;
import com.example.repository.CustomerRepository;
import com.example.repository.DeliveryRepository;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class OrderMapper {
private final CustomerRepository customerRepository;
private final DeliveryRepository deliveryRepository;
private final CustomerMapper customerMapper;
private final DeliveryMapper deliveryMapper;
public OrderMapper(CustomerRepository customerRepository,
DeliveryRepository deliveryRepository,
CustomerMapper customerMapper,
DeliveryMapper deliveryMapper) {
this.customerRepository = customerRepository;
this.deliveryRepository = deliveryRepository;
this.customerMapper = customerMapper;
this.deliveryMapper = deliveryMapper;
}
public Order toEntity(OrderRq orderRq) {
Optional<Customer> customer = customerRepository.findById(orderRq.getCustomerId());
Optional<Delivery> delivery = deliveryRepository.findById(orderRq.getDeliveryId());
if (customer.isEmpty() || delivery.isEmpty()) {
throw new IllegalArgumentException("Customer или Delivery не найдены");
}
Order order = new Order();
order.setCustomer(customer.get());
order.setDelivery(delivery.get());
order.setStatus(orderRq.getStatus());
return order;
}
public OrderRs toResponse(Order order) {
OrderRs orderRs = new OrderRs();
orderRs.setId(order.getId());
CustomerRs customerRs = customerMapper.toResponse(order.getCustomer());
DeliveryRs deliveryRs = deliveryMapper.toResponse(order.getDelivery());
orderRs.setCustomer(customerRs);
orderRs.setDelivery(deliveryRs);
orderRs.setStatus(order.getStatus());
return orderRs;
}
}

View File

@@ -0,0 +1,12 @@
package com.example.repository;
import java.util.List;
import java.util.Optional;
public interface CommonRepository<T> {
List<T> findAll();
Optional<T> findById(String id);
T save(T entity);
void deleteById(String id);
boolean existsById(String id);
}

View File

@@ -0,0 +1,15 @@
package com.example.repository;
import com.example.entity.Customer;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public class CustomerRepository extends MapRepository<Customer> {
public Optional<Customer> findByEmail(String email) {
return storage.values().stream()
.filter(customer -> customer.getEmail().equals(email))
.findFirst();
}
}

View File

@@ -0,0 +1,15 @@
package com.example.repository;
import com.example.entity.Delivery;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public class DeliveryRepository extends MapRepository<Delivery> {
public Optional<Delivery> findByTrackingNumber(String trackingNumber) {
return storage.values().stream()
.filter(delivery -> delivery.getTrackingNumber().equals(trackingNumber))
.findFirst();
}
}

View File

@@ -0,0 +1,43 @@
package com.example.repository;
import com.example.entity.BaseEntity;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
public abstract class MapRepository<T extends BaseEntity> implements CommonRepository<T> {
protected final ConcurrentHashMap<String, T> storage = new ConcurrentHashMap<>();
protected final AtomicLong idCounter = new AtomicLong(1);
@Override
public List<T> findAll() {
return new ArrayList<>(storage.values());
}
@Override
public Optional<T> findById(String id) {
return Optional.ofNullable(storage.get(id));
}
@Override
public T save(T entity) {
if (entity.getId() == null) {
entity.setId(String.valueOf(idCounter.getAndIncrement()));
}
storage.put(entity.getId(), entity);
return entity;
}
@Override
public void deleteById(String id) {
storage.remove(id);
}
@Override
public boolean existsById(String id) {
return storage.containsKey(id);
}
}

View File

@@ -0,0 +1,29 @@
package com.example.repository;
import com.example.entity.Order;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public class OrderRepository extends MapRepository<Order> {
public List<Order> findByCustomerId(String customerId) {
return storage.values().stream()
.filter(order -> order.getCustomer().getId().equals(customerId))
.toList();
}
public List<Order> findByDeliveryId(String deliveryId) {
return storage.values().stream()
.filter(order -> order.getDelivery().getId().equals(deliveryId))
.toList();
}
public List<Order> findByStatus(String status) {
return storage.values().stream()
.filter(order -> order.getStatus().equals(status))
.toList();
}
}

View File

@@ -0,0 +1,70 @@
package com.example.service;
import com.example.entity.Customer;
import com.example.dto.CustomerRq;
import com.example.dto.CustomerRs;
import com.example.mapper.CustomerMapper;
import com.example.repository.CustomerRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class CustomerService {
private final CustomerRepository customerRepository;
private final CustomerMapper customerMapper;
public CustomerService(CustomerRepository customerRepository, CustomerMapper customerMapper) {
this.customerRepository = customerRepository;
this.customerMapper = customerMapper;
initializeTestData();
}
private void initializeTestData() {
if (customerRepository.findAll().isEmpty()) {
Customer customer1 = new Customer("Иванов Иван", "ivanov@example.com");
Customer customer2 = new Customer("Петров Петр", "petrov@example.com");
Customer customer3 = new Customer("Олег Андреевич", "oleg@example.com");
customerRepository.save(customer1);
customerRepository.save(customer2);
customerRepository.save(customer3);
}
}
public List<CustomerRs> findAll() {
return customerRepository.findAll().stream()
.map(customerMapper::toResponse)
.toList();
}
public Optional<CustomerRs> findById(String id) {
return customerRepository.findById(id)
.map(customerMapper::toResponse);
}
public CustomerRs create(CustomerRq customerRq) {
Customer customer = customerMapper.toEntity(customerRq);
Customer saved = customerRepository.save(customer);
return customerMapper.toResponse(saved);
}
public Optional<CustomerRs> update(String id, CustomerRq customerRq) {
return customerRepository.findById(id)
.map(customer -> {
customer.setName(customerRq.getName());
customer.setEmail(customerRq.getEmail());
Customer updated = customerRepository.save(customer);
return customerMapper.toResponse(updated);
});
}
public boolean delete(String id) {
if (customerRepository.existsById(id)) {
customerRepository.deleteById(id);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,70 @@
package com.example.service;
import com.example.entity.Delivery;
import com.example.dto.DeliveryRq;
import com.example.dto.DeliveryRs;
import com.example.mapper.DeliveryMapper;
import com.example.repository.DeliveryRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class DeliveryService {
private final DeliveryRepository deliveryRepository;
private final DeliveryMapper deliveryMapper;
public DeliveryService(DeliveryRepository deliveryRepository, DeliveryMapper deliveryMapper) {
this.deliveryRepository = deliveryRepository;
this.deliveryMapper = deliveryMapper;
initializeTestData();
}
private void initializeTestData() {
if (deliveryRepository.findAll().isEmpty()) {
Delivery delivery1 = new Delivery("IVN012021", "гоголя10", "Доставлено", "Парт петрович wwww");
Delivery delivery2 = new Delivery("IVN123456", "Москва", "В пути", "1Иванов Иван");
deliveryRepository.save(delivery1);
deliveryRepository.save(delivery2);
}
}
public List<DeliveryRs> findAll() {
return deliveryRepository.findAll().stream()
.map(deliveryMapper::toResponse)
.toList();
}
public Optional<DeliveryRs> findById(String id) {
return deliveryRepository.findById(id)
.map(deliveryMapper::toResponse);
}
public DeliveryRs create(DeliveryRq deliveryRq) {
Delivery delivery = deliveryMapper.toEntity(deliveryRq);
Delivery saved = deliveryRepository.save(delivery);
return deliveryMapper.toResponse(saved);
}
public Optional<DeliveryRs> update(String id, DeliveryRq deliveryRq) {
return deliveryRepository.findById(id)
.map(delivery -> {
delivery.setTrackingNumber(deliveryRq.getTrackingNumber());
delivery.setDestination(deliveryRq.getDestination());
delivery.setStatus(deliveryRq.getStatus());
delivery.setCustomer(deliveryRq.getCustomer());
Delivery updated = deliveryRepository.save(delivery);
return deliveryMapper.toResponse(updated);
});
}
public boolean delete(String id) {
if (deliveryRepository.existsById(id)) {
deliveryRepository.deleteById(id);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,97 @@
package com.example.service;
import com.example.entity.Order;
import com.example.entity.Customer;
import com.example.entity.Delivery;
import com.example.dto.OrderRq;
import com.example.dto.OrderRs;
import com.example.mapper.OrderMapper;
import com.example.repository.OrderRepository;
import com.example.repository.CustomerRepository;
import com.example.repository.DeliveryRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class OrderService {
private final OrderRepository orderRepository;
private final CustomerRepository customerRepository;
private final DeliveryRepository deliveryRepository;
private final OrderMapper orderMapper;
public OrderService(OrderRepository orderRepository,
CustomerRepository customerRepository,
DeliveryRepository deliveryRepository,
OrderMapper orderMapper) {
this.orderRepository = orderRepository;
this.customerRepository = customerRepository;
this.deliveryRepository = deliveryRepository;
this.orderMapper = orderMapper;
initializeTestData();
}
private void initializeTestData() {
if (orderRepository.findAll().isEmpty()) {
// Берем тестовых клиентов и доставки
List<Customer> customers = customerRepository.findAll();
List<Delivery> deliveries = deliveryRepository.findAll();
if (!customers.isEmpty() && !deliveries.isEmpty()) {
Order order1 = new Order(customers.get(0), deliveries.get(0), "Доставлено");
Order order2 = new Order(customers.get(1), deliveries.get(1), "В пути");
orderRepository.save(order1);
orderRepository.save(order2);
}
}
}
public List<OrderRs> findAll() {
return orderRepository.findAll().stream()
.map(orderMapper::toResponse)
.toList();
}
public Optional<OrderRs> findById(String id) {
return orderRepository.findById(id)
.map(orderMapper::toResponse);
}
public List<OrderRs> findByCustomerId(String customerId) {
return orderRepository.findByCustomerId(customerId).stream()
.map(orderMapper::toResponse)
.toList();
}
public List<OrderRs> findByStatus(String status) {
return orderRepository.findByStatus(status).stream()
.map(orderMapper::toResponse)
.toList();
}
public OrderRs create(OrderRq orderRq) {
Order order = orderMapper.toEntity(orderRq);
Order saved = orderRepository.save(order);
return orderMapper.toResponse(saved);
}
public Optional<OrderRs> update(String id, OrderRq orderRq) {
return orderRepository.findById(id)
.map(order -> {
Order updatedOrder = orderMapper.toEntity(orderRq);
updatedOrder.setId(id); // Сохраняем оригинальный ID
Order saved = orderRepository.save(updatedOrder);
return orderMapper.toResponse(saved);
});
}
public boolean delete(String id) {
if (orderRepository.existsById(id)) {
orderRepository.deleteById(id);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,5 @@
package com.example.controller;
public class CustomerControllerTest {
}

View File

@@ -0,0 +1,5 @@
package com.example.controller;
public class DeliveryControllerTest {
}

View File

@@ -0,0 +1,5 @@
package com.example.controller;
public class OrderControllerTest {
}

View File

@@ -1,13 +0,0 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DemoApplicationTests {
@Test
void contextLoads() {
}
}

Some files were not shown because too many files have changed in this diff Show More