Yuli Shlosberg | a4eeb11 | 2019-01-07 16:23:36 +0200 | [diff] [blame^] | 1 | package org.onap.sdc.security; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import java.io.IOException; |
| 6 | import java.util.HashSet; |
| 7 | import java.util.Set; |
| 8 | |
| 9 | import static org.junit.Assert.assertTrue; |
| 10 | |
| 11 | public class RepresentationUtilsTest { |
| 12 | |
| 13 | private static AuthenticationCookie originalCookie = new AuthenticationCookie("kuku"); |
| 14 | |
| 15 | @Test |
| 16 | public void representationE2EwithRoleNull() throws IOException { |
| 17 | originalCookie.setRoles(null); |
| 18 | String jsonStr = RepresentationUtils.toRepresentation(originalCookie); |
| 19 | AuthenticationCookie cookieFromJson = RepresentationUtils.fromRepresentation(jsonStr, AuthenticationCookie.class); |
| 20 | assertTrue(originalCookie.equals(cookieFromJson)); |
| 21 | } |
| 22 | |
| 23 | @Test |
| 24 | public void representationE2EwithRoleNotNull() throws IOException { |
| 25 | Set<String> roles = new HashSet<String>(); |
| 26 | roles.add("Designer"); |
| 27 | roles.add("Admin"); |
| 28 | roles.add("Tester"); |
| 29 | originalCookie.setRoles(roles); |
| 30 | String jsonStr = RepresentationUtils.toRepresentation(originalCookie); |
| 31 | AuthenticationCookie cookieFromJson = RepresentationUtils.fromRepresentation(jsonStr, AuthenticationCookie.class); |
| 32 | assertTrue(originalCookie.equals(cookieFromJson)); |
| 33 | } |
| 34 | } |