Pushing local changes to the remote repository for TestDefaultSystemScopeService

pull/1367/head
Aishwarya Gosavi 2018-03-04 13:56:54 -05:00
parent f26f6db319
commit e0038e3462
1 changed files with 61 additions and 2 deletions

View File

@ -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<SystemScope> allScopesWithValue;
private Set<String> 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<SystemScope> unRestrictedScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, dynScope1);
assertThat(service.removeRestrictedAndReservedScopes(allScopes),equalTo(unRestrictedScopes));
}
@Test
public void removeReservedScopes() {
Set<SystemScope> 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));
}
}