Subject: [PATCH] 5_jaxb_test
---
Index: src/test/java/ru/javaops/docjava/TestData.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/test/java/ru/javaops/docjava/TestData.java b/src/test/java/ru/javaops/docjava/TestData.java
new file mode 100644
--- /dev/null	(date 1695982244294)
+++ b/src/test/java/ru/javaops/docjava/TestData.java	(date 1695982244294)
@@ -0,0 +1,42 @@
+package ru.javaops.docjava;
+
+import ru.javaops.docjava.schema.Meal;
+import ru.javaops.docjava.schema.Meals;
+import ru.javaops.docjava.schema.RoleTypes;
+import ru.javaops.docjava.schema.User;
+
+import java.io.File;
+import java.time.Month;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import static java.time.LocalDateTime.of;
+
+public class TestData {
+    public static final File inputFile = new File("in/usersWithMeals.xml");
+
+    public static final Date registered = new Date(123, Calendar.JANUARY, 1, 13, 0, 0);
+
+    public static final Meals userMeals = new Meals(List.of(
+            new Meal("Завтрак", 500, of(2023, Month.JANUARY, 30, 10, 0, 0), null),
+            new Meal("Обед", 1000, of(2023, Month.JANUARY, 30, 13, 0, 0), null),
+            new Meal("Ужин", 500, of(2023, Month.JANUARY, 30, 20, 0, 0), null),
+            new Meal("Еда на граничное значение", 100, of(2023, Month.JANUARY, 31, 0, 0, 0), null),
+            new Meal("Завтрак", 500, of(2023, Month.JANUARY, 31, 10, 0, 0), null),
+            new Meal("Обед", 1000, of(2023, Month.JANUARY, 31, 13, 0, 0), null),
+            new Meal("Ужин", 510, of(2023, Month.JANUARY, 31, 20, 0, 0), null)
+    ));
+    public static final User user = new User("User", "user@yandex.ru", "password", 2005, registered, true,
+            List.of(RoleTypes.USER), userMeals);
+
+    public static final Meals adminMeals = new Meals(List.of(
+            new Meal("Админ ланч", 510, of(2023, Month.JANUARY, 30, 14, 0, 0), null),
+            new Meal("Админ ужин", 730, of(2023, Month.JANUARY, 30, 21, 0, 0), null)
+    ));
+    public static final User admin = new User("Admin", "admin@gmail.com", "admin", 1900, registered, true,
+            List.of(RoleTypes.ADMIN, RoleTypes.USER), adminMeals);
+
+    public static final User guest = new User("Guest", "guest@gmail.com", "guest", 2000, registered, false,
+            List.of(), null);
+}
\ No newline at end of file
Index: src/test/java/ru/javaops/docjava/xml/jaxb/JaxbUtilTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/test/java/ru/javaops/docjava/xml/jaxb/JaxbUtilTest.java b/src/test/java/ru/javaops/docjava/xml/jaxb/JaxbUtilTest.java
new file mode 100644
--- /dev/null	(date 1695982150464)
+++ b/src/test/java/ru/javaops/docjava/xml/jaxb/JaxbUtilTest.java	(date 1695982150464)
@@ -0,0 +1,29 @@
+package ru.javaops.docjava.xml.jaxb;
+
+import jakarta.xml.bind.JAXBException;
+import jakarta.xml.bind.UnmarshalException;
+import org.junit.jupiter.api.Test;
+import ru.javaops.docjava.schema.UsersWithMeals;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static ru.javaops.docjava.TestData.*;
+
+public class JaxbUtilTest {
+
+    @Test
+    public void unmarshalOK() throws JAXBException, IOException {
+        UsersWithMeals usersWithMeals = JaxbUtil.unmarshal(inputFile);
+        assertEquals(new UsersWithMeals.Users(List.of(user, admin, guest)), usersWithMeals.getUsers());
+    }
+
+    @Test
+    void unmarshalNOK() {
+        assertThrows(UnmarshalException.class,
+                () -> JaxbUtil.unmarshal(new File("in/badXmlFile.xml")), "Except bad format exception");
+    }
+}
\ No newline at end of file
Index: src/test/java/ru/javaops/docjava/xml/xsd/SchemaUtilTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/test/java/ru/javaops/docjava/xml/xsd/SchemaUtilTest.java b/src/test/java/ru/javaops/docjava/xml/xsd/SchemaUtilTest.java
--- a/src/test/java/ru/javaops/docjava/xml/xsd/SchemaUtilTest.java	(revision 28466f7dd83ef70b5186a5d9bdee4664fb266896)
+++ b/src/test/java/ru/javaops/docjava/xml/xsd/SchemaUtilTest.java	(date 1695982201062)
@@ -8,13 +8,14 @@
 import java.io.IOException;
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static ru.javaops.docjava.TestData.inputFile;
 
 class SchemaUtilTest {
     private static final File xmlSchema = new File("in/usersWithMeals.xsd");
 
     @Test
     void validateOK() throws IOException, SAXException {
-        SchemaUtil.validate(new File("in/usersWithMeals.xml"), xmlSchema);
+        SchemaUtil.validate(inputFile, xmlSchema);
     }
 
     @Test
Index: src/main/java/ru/javaops/docjava/schema/Meals.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/ru/javaops/docjava/schema/Meals.java b/src/main/java/ru/javaops/docjava/schema/Meals.java
--- a/src/main/java/ru/javaops/docjava/schema/Meals.java	(revision 28466f7dd83ef70b5186a5d9bdee4664fb266896)
+++ b/src/main/java/ru/javaops/docjava/schema/Meals.java	(date 1695982150453)
@@ -5,6 +5,7 @@
 import jakarta.xml.bind.annotation.XmlAccessorType;
 import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlRootElement;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
@@ -15,6 +16,7 @@
 @XmlRootElement(name = "Meals", namespace = "http://javaops.ru")
 @Data
 @NoArgsConstructor
+@AllArgsConstructor
 public class Meals {
     @XmlElement(name = "Meal", namespace = "http://javaops.ru")
     protected List<Meal> meal = new ArrayList<>();
Index: src/main/java/ru/javaops/docjava/schema/Meal.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/ru/javaops/docjava/schema/Meal.java b/src/main/java/ru/javaops/docjava/schema/Meal.java
--- a/src/main/java/ru/javaops/docjava/schema/Meal.java	(revision 28466f7dd83ef70b5186a5d9bdee4664fb266896)
+++ b/src/main/java/ru/javaops/docjava/schema/Meal.java	(date 1695982150449)
@@ -2,6 +2,7 @@
 
 import jakarta.xml.bind.annotation.*;
 import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
@@ -11,6 +12,7 @@
 @XmlRootElement(name = "Meal", namespace = "http://javaops.ru")
 @Data
 @NoArgsConstructor
+@AllArgsConstructor
 public class Meal {
     @XmlValue
     protected String value;
Index: src/main/java/ru/javaops/docjava/schema/UsersWithMeals.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/ru/javaops/docjava/schema/UsersWithMeals.java b/src/main/java/ru/javaops/docjava/schema/UsersWithMeals.java
--- a/src/main/java/ru/javaops/docjava/schema/UsersWithMeals.java	(revision 28466f7dd83ef70b5186a5d9bdee4664fb266896)
+++ b/src/main/java/ru/javaops/docjava/schema/UsersWithMeals.java	(date 1695982150461)
@@ -4,6 +4,7 @@
 import jakarta.xml.bind.annotation.XmlAccessorType;
 import jakarta.xml.bind.annotation.XmlElement;
 import jakarta.xml.bind.annotation.XmlRootElement;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
@@ -21,6 +22,7 @@
     @XmlAccessorType(XmlAccessType.FIELD)
     @Data
     @NoArgsConstructor
+    @AllArgsConstructor
     public static class Users {
         @XmlElement(name = "User", namespace = "http://javaops.ru")
         protected List<User> user = new ArrayList<>();
Index: src/main/java/ru/javaops/docjava/schema/User.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/ru/javaops/docjava/schema/User.java b/src/main/java/ru/javaops/docjava/schema/User.java
--- a/src/main/java/ru/javaops/docjava/schema/User.java	(revision 28466f7dd83ef70b5186a5d9bdee4664fb266896)
+++ b/src/main/java/ru/javaops/docjava/schema/User.java	(date 1695982150457)
@@ -1,6 +1,7 @@
 package ru.javaops.docjava.schema;
 
 import jakarta.xml.bind.annotation.*;
+import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
@@ -12,6 +13,7 @@
 @XmlRootElement(name = "User", namespace = "http://javaops.ru")
 @Data
 @NoArgsConstructor
+@AllArgsConstructor
 public class User {
     @XmlAttribute(name = "name", required = true)
     protected String name;
