package by.bsuir.mpp.computershop;

import by.bsuir.mpp.computershop.config.PrimaryConfiguration;
import by.bsuir.mpp.computershop.dto.full.AssemblyComponentFullDto;
import by.bsuir.mpp.computershop.entity.Assembly;
import by.bsuir.mpp.computershop.entity.AssemblyComponent;
import ma.glasnost.orika.MapperFacade;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Random;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {PrimaryConfiguration.class})
@SpringBootTest
public class MapperTests {

    private final Random rnd = new Random();

    @Autowired
    private MapperFacade mapper;

    @Test
    public void contextLoads() {
    }

    @Test
    public void assemblyComponentMappingTest() {
        Assembly asm = new Assembly();
        asm.setId(getNextId());

        AssemblyComponent expected = new AssemblyComponent();
        expected.setAssembly(asm);

        AssemblyComponentFullDto intermediate = mapper.map(expected, AssemblyComponentFullDto.class);
        Assert.assertEquals(expected.getAssembly().getId(), intermediate.getAssemblyId());

        AssemblyComponent result = mapper.map(intermediate, AssemblyComponent.class);
        Assert.assertEquals(expected.getId(), result.getId());
        Assert.assertEquals(expected.getAssembly().getId(), result.getAssembly().getId());
    }

    private Long getNextId() {
        return rnd.nextLong() + 1;
    }
}

@@ -159,16 +159,75 @@
 ullDto;%0A
+import by.bsuir.mpp.computershop.dto.full.UserAuthFullDto;%0A
 import b
@@ -327,16 +327,117 @@
 ponent;%0A
+import by.bsuir.mpp.computershop.entity.UserAuth;%0Aimport by.bsuir.mpp.computershop.utils.TestHelper;%0A
 import m
@@ -668,24 +668,93 @@
 ngBootTest;%0A
+import org.springframework.security.crypto.password.PasswordEncoder;%0A
 import org.s
@@ -869,34 +869,8 @@
 r;%0A%0A
-import java.util.Random;%0A%0A
 @Run
@@ -1004,54 +1004,8 @@
  %7B%0A%0A
-    private final Random rnd = new Random();%0A%0A
     
@@ -1058,51 +1058,62 @@
    @
-Test%0A    public void contextLoads() %7B%0A    %7D
+Autowired%0A    private PasswordEncoder passwordEncoder;
 %0A%0A  
@@ -1226,23 +1226,35 @@
 m.setId(
-getNext
+TestHelper.nextLong
 Id());%0A%0A
@@ -1623,32 +1623,33 @@
 mponent.class);%0A
+%0A
         Assert.a
@@ -1801,68 +1801,555 @@
     
-private Long getNextId() %7B%0A        return rnd.nextLong() + 1
+@Test%0A    public void userAuthConverterTest() %7B%0A        UserAuthFullDto sourceAuthDto = TestHelper.nextUserAuthFullDto();%0A%0A        UserAuth entity = mapper.map(sourceAuthDto, UserAuth.class);%0A%0A        Assert.assertEquals(entity.getEmail(), sourceAuthDto.getEmail());%0A        Assert.assertEquals(entity.getRole(), sourceAuthDto.getRole());%0A        Assert.assertEquals(entity.getUserInfo().getFirstName(), sourceAuthDto.getUserInfo().getFirstName());%0A%0A        Assert.assertTrue(passwordEncoder.matches(sourceAuthDto.getPass(), entity.getPassHash()))
 ;%0A  

Update MapperTests