package com.ip_b1.fii.admission;

import com.ip_b1.fii.admission.Controllers.SaveForm;
import com.ip_b1.fii.admission.DTO.AuthEntity;
import com.ip_b1.fii.admission.DTO.FormEntity;
import com.ip_b1.fii.admission.DTO.SaveFormOutEntity;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * Created by ddpv on 5/14/2017.
 */
public class SaveFormTest {
    private SaveForm test;
    private FormEntity formEntity;

    @BeforeEach
    private void setUp(){
        test = new SaveForm();
        formEntity = new FormEntity();
    }
    @AfterEach
    private void tearDown(){
        formEntity = null;
        test = null;
    }

    @Test
    public void unauthorized_user() {
        AuthEntity testEntity = new AuthEntity("alexd@info.uaic.ro", "some_invalid_token");
        formEntity.setAuth(testEntity);
        ResponseEntity<SaveFormOutEntity> testResult = test.testLogin(formEntity);
        Assert.assertEquals(HttpStatus.UNAUTHORIZED, testResult.getStatusCode());
    }

    @Test
    public void authorized_user() {
        AuthEntity testEntity = new AuthEntity("alexd@info.uaic.ro", "valid_token");
        formEntity.setAuth(testEntity);
        ResponseEntity<SaveFormOutEntity> testResult = test.testLogin(formEntity);
        Assert.assertEquals(HttpStatus.OK, testResult.getStatusCode());
    }

}

@@ -463,16 +463,59 @@
 ity;%0D%0A%0D%0A
+import javax.xml.ws.http.HTTPException;%0D%0A%0D%0A
 /**%0D%0A * 
@@ -725,48 +725,8 @@
 );%0D%0A
-        formEntity = new FormEntity();%0D%0A
     
@@ -775,37 +775,10 @@
 wn()
+ 
 %7B
-%0D%0A        formEntity = null;
 %0D%0A  
@@ -856,34 +856,108 @@
 er() %7B%0D%0A
-        AuthEntity
+%0D%0A        test = new SaveForm();%0D%0A        AuthEntity testEntity;%0D%0A        try %7B%0D%0A           
  testEnt
@@ -971,36 +971,36 @@
 ew AuthEntity(%22a
-lexd
+dmin
 @info.uaic.ro%22, 
@@ -1004,26 +1004,12 @@
 %22, %22
-some_invalid_token
+tkek
 %22);%0D
@@ -1018,52 +1018,15 @@
     
-   formEntity.setAuth(testEntity);%0D%0A
        
- 
 Resp
@@ -1075,33 +1075,37 @@
  test.testLogin(
-f
+new F
 ormEntity);%0D%0A   
@@ -1089,36 +1089,169 @@
 n(new FormEntity
+()
 );%0D%0A
+            Assert.assertNotEquals(HttpStatus.OK, testResult.getStatusCode());%0D%0A%0D%0A        %7D%0D%0A        catch(HTTPException e) %7B%0D%0A    
         Assert.a
@@ -1287,26 +1287,17 @@
 ORIZED, 
-testResult
+e
 .getStat
@@ -1300,32 +1300,45 @@
 StatusCode());%0D%0A
+        %7D%0D%0A%0D%0A
     %7D%0D%0A%0D%0A    @Te
@@ -1357,35 +1357,59 @@
 ic void 
-authorized_user() %7B
+test_ok() %7B%0D%0A        test = new SaveForm();
 %0D%0A      
@@ -1455,12 +1455,12 @@
 y(%22a
-lexd
+dmin
 @inf
@@ -1476,65 +1476,19 @@
 %22, %22
-valid_
 to
+p
 ke
-n
+k
 %22);%0D%0A
-        formEntity.setAuth(testEntity);%0D%0A
     
@@ -1553,17 +1553,21 @@
 stLogin(
-f
+new F
 ormEntit
@@ -1567,16 +1567,18 @@
 rmEntity
+()
 );%0D%0A    
@@ -1594,37 +1594,91 @@
 t.assert
-Equals(HttpStatus.OK,
+True(HttpStatus.OK == testResult.getStatusCode() %7C%7C HttpStatus.NOT_FOUND ==
  testRes

Update SaveFormTest.java