| margaretha | 45211af | 2018-08-28 12:49:07 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.misc; |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 2 | |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| Michael Hanl | 2c3b0b1 | 2016-07-01 18:30:12 +0200 | [diff] [blame] | 4 | import static org.junit.Assert.assertNotNull; |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 5 | |
| 6 | import org.apache.commons.codec.binary.Base64; |
| 7 | import org.junit.Test; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | |
| 10 | import de.ids_mannheim.korap.authentication.BasicAuthentication; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 11 | import de.ids_mannheim.korap.authentication.http.AuthorizationData; |
| 12 | import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler; |
| 13 | import de.ids_mannheim.korap.authentication.http.TransferEncoding; |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 14 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| 15 | import de.ids_mannheim.korap.utils.StringUtils; |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Created by hanl on 29.05.16. |
| 19 | */ |
| 20 | public class StringUtilsTest { |
| 21 | |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 22 | |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 23 | @Test |
| 24 | public void testTextIToDoc () { |
| 25 | String textSigle = "WPD_AAA.02439"; |
| 26 | String docSigle = "WPD_AAA"; |
| 27 | assertEquals(docSigle, StringUtils.getDocSigle(textSigle)); |
| 28 | assertEquals(docSigle, StringUtils.getDocSigle(docSigle)); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | @Test |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 33 | public void testBasicHttpSplit () throws KustvaktException { |
| 34 | TransferEncoding transferEncoding = new TransferEncoding(); |
| 35 | String s2 = new String(Base64.encodeBase64("test:testPass".getBytes())); |
| 36 | String[] f2 = transferEncoding.decodeBase64(s2); |
| 37 | assertEquals("test", f2[0]); |
| 38 | assertEquals("testPass", f2[1]); |
| 39 | |
| 40 | |
| 41 | HttpAuthorizationHandler handler = new HttpAuthorizationHandler(); |
| 42 | String s1 = "basic " |
| 43 | + new String(Base64.encodeBase64("test:testPass".getBytes())); |
| margaretha | 2afb97d | 2017-12-07 19:18:44 +0100 | [diff] [blame] | 44 | AuthorizationData f1 = handler.parseAuthorizationHeaderValue(s1); |
| margaretha | 4b5c141 | 2017-11-15 20:55:04 +0100 | [diff] [blame] | 45 | assertEquals(s2, f1.getToken()); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 46 | } |
| Michael Hanl | 2c3b0b1 | 2016-07-01 18:30:12 +0200 | [diff] [blame] | 47 | |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 48 | } |