|
| 1 | +package org.oidc.service.base; |
| 2 | + |
| 3 | +import com.auth0.msg.KeyJar; |
| 4 | +import org.junit.Assert; |
| 5 | +import org.junit.Rule; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.rules.ExpectedException; |
| 8 | +import org.oidc.common.ValueError; |
| 9 | + |
| 10 | +public class ServiceContextTest { |
| 11 | + |
| 12 | + @Rule |
| 13 | + public ExpectedException thrown = ExpectedException.none(); |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testFileNameFromWebnameNullUrl() throws Exception{ |
| 17 | + thrown.expect(IllegalArgumentException.class); |
| 18 | + thrown.expectMessage("null or empty webName"); |
| 19 | + ServiceContext serviceContext = new ServiceContext(); |
| 20 | + serviceContext.fileNameFromWebname(null); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testFileNameFromWebnameEmptyUrl() throws Exception{ |
| 25 | + thrown.expect(IllegalArgumentException.class); |
| 26 | + thrown.expectMessage("null or empty webName"); |
| 27 | + ServiceContext serviceContext = new ServiceContext(); |
| 28 | + serviceContext.fileNameFromWebname(""); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testFileNameFromWebnameWhereWebNameDoesntStartWithBaseUrl() throws Exception { |
| 33 | + thrown.expect(ValueError.class); |
| 34 | + thrown.expectMessage("Webname does not match baseUrl"); |
| 35 | + ServiceContextConfig serviceContextConfig = new ServiceContextConfig.ServiceContextConfigBuilder().setBaseUrl("baseUrl") |
| 36 | + .buildServiceContext(); |
| 37 | + KeyJar keyJar = new KeyJar(); |
| 38 | + ServiceContext serviceContext = new ServiceContext(keyJar, serviceContextConfig); |
| 39 | + serviceContext.fileNameFromWebname("webName"); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testFileNameFromWebnameWhereWebNameStartsWithForwardSlash() throws Exception { |
| 44 | + ServiceContextConfig serviceContextConfig = new ServiceContextConfig.ServiceContextConfigBuilder().setBaseUrl("www.yahoo.com") |
| 45 | + .buildServiceContext(); |
| 46 | + KeyJar keyJar = new KeyJar(); |
| 47 | + ServiceContext serviceContext = new ServiceContext(keyJar, serviceContextConfig); |
| 48 | + String fileName = serviceContext.fileNameFromWebname("www.yahoo.com/1234"); |
| 49 | + Assert.assertTrue(fileName.equals("1234")); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testFileNameFromWebnameWhereWebNameDoesntStartsWithForwardSlash() throws Exception { |
| 54 | + ServiceContextConfig serviceContextConfig = new ServiceContextConfig.ServiceContextConfigBuilder().setBaseUrl("www.yahoo.com") |
| 55 | + .buildServiceContext(); |
| 56 | + KeyJar keyJar = new KeyJar(); |
| 57 | + ServiceContext serviceContext = new ServiceContext(keyJar, serviceContextConfig); |
| 58 | + String fileName = serviceContext.fileNameFromWebname("www.yahoo.com:1234"); |
| 59 | + Assert.assertTrue(fileName.equals(":1234")); |
| 60 | + } |
| 61 | +} |
0 commit comments