From e0038e3462b46f5814784804d54f1e349f309587 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sun, 4 Mar 2018 13:56:54 -0500 Subject: [PATCH] Pushing local changes to the remote repository for TestDefaultSystemScopeService --- .../impl/TestDefaultSystemScopeService.java | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 808d96b58..6c3063416 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2018 The MIT Internet Trust Consortium + * Copyright 2017 The MIT Internet Trust Consortium * * Portions copyright 2011-2013 The MITRE Corporation * @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mitre.oauth2.model.SystemScope; import org.mitre.oauth2.repository.SystemScopeRepository; +import org.mitre.oauth2.service.SystemScopeService; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -34,6 +35,8 @@ import com.google.common.collect.Sets; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.notNullValue; + import static org.junit.Assert.assertThat; @@ -51,7 +54,8 @@ public class TestDefaultSystemScopeService { private SystemScope defaultScope2; private SystemScope dynScope1; private SystemScope restrictedScope1; - + private SystemScope mySystemScope; + private String defaultDynScope1String = "defaultDynScope1"; private String defaultDynScope2String = "defaultDynScope2"; private String defaultScope1String = "defaultScope1"; @@ -64,6 +68,7 @@ public class TestDefaultSystemScopeService { private Set allScopesWithValue; private Set allScopeStringsWithValue; + @Mock private SystemScopeRepository repository; @@ -83,7 +88,9 @@ public class TestDefaultSystemScopeService { defaultDynScope2 = new SystemScope(defaultDynScope2String); defaultDynScope1.setDefaultScope(true); defaultDynScope2.setDefaultScope(true); + mySystemScope = new SystemScope(); + // two strictly default scopes (restricted) defaultScope1 = new SystemScope(defaultScope1String); defaultScope2 = new SystemScope(defaultScope2String); @@ -114,6 +121,8 @@ public class TestDefaultSystemScopeService { Mockito.when(repository.getByValue(restrictedScope1String)).thenReturn(restrictedScope1); Mockito.when(repository.getAll()).thenReturn(allScopes); + Mockito.when(repository.save(mySystemScope)).thenReturn(mySystemScope); + } @Test @@ -185,5 +194,55 @@ public class TestDefaultSystemScopeService { // extra scope (fail) assertThat(service.scopesMatch(expected, actualBad), is(false)); } + + @Test + public void removeRestrictedAndReservedScopes() { + + Set unRestrictedScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, dynScope1); + assertThat(service.removeRestrictedAndReservedScopes(allScopes),equalTo(unRestrictedScopes)); + } + + @Test + public void removeReservedScopes() { + Set unReservedScopes = Sets.newHashSet(defaultDynScope2, defaultDynScope1, defaultScope2,restrictedScope1,defaultScope1,dynScope1); + assertThat(service.removeReservedScopes(allScopes), equalTo(unReservedScopes)); + } + + @Test + public void getById_notfound() { + + // check null condition + assertThat(service.getById((long) 60), is(nullValue())); + + + } + + @Test + public void getByValue_notfound() { + + // check null condition + + assertThat(service.getByValue("defaultDynScope1String"), is(nullValue())); + + + } + + @Test + public void save_null() { + // check null condition + assertThat(service.save(defaultScope1), is(nullValue())); + + } + + @Test + public void save_value() { + assertThat(service.save(mySystemScope), equalTo(mySystemScope)); + } + + @Test + public void getReserveScopes() { + assertThat(service.getReserved(), equalTo(SystemScopeService.reservedScopes)); + + } }