-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use the ide-login library * Fail login if it seems already in progress * Convert GoogleLoginService into OGSi service * Use OSGi Declarative Services * Pull jackson-core-asl from Maven Central * Refactor / enhance code design * Make ShellProvider return shells dynamically
- Loading branch information
1 parent
03dc122
commit ae58737
Showing
32 changed files
with
638 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...login.test/src/com/google/cloud/tools/eclipse/appengine/login/GoogleLoginServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/******************************************************************************* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*******************************************************************************/ | ||
|
||
package com.google.cloud.tools.eclipse.appengine.login; | ||
|
||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.cloud.tools.eclipse.appengine.login.ui.LoginServiceUi; | ||
import com.google.cloud.tools.ide.login.LoggerFacade; | ||
import com.google.cloud.tools.ide.login.OAuthData; | ||
import com.google.cloud.tools.ide.login.OAuthDataStore; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class GoogleLoginServiceTest { | ||
|
||
@Mock private OAuthDataStore dataStore; | ||
@Mock private OAuthData savedOAuthData; | ||
@Mock private LoginServiceUi uiFacade; | ||
@Mock private LoggerFacade loggerFacade; | ||
|
||
private static final SortedSet<String> OAUTH_SCOPES = Collections.unmodifiableSortedSet( | ||
new TreeSet<>(Arrays.asList( | ||
"email", | ||
"https://www.googleapis.com/auth/cloud-platform" | ||
))); | ||
|
||
@Before | ||
public void setUp() { | ||
when(dataStore.loadOAuthData()).thenReturn(savedOAuthData); | ||
} | ||
|
||
@Test | ||
public void testGoogleLoginService_clearSavedCredentialIfNullRefreshToken() { | ||
when(savedOAuthData.getRefreshToken()).thenReturn(null); | ||
|
||
GoogleLoginService loginService = new GoogleLoginService(dataStore, uiFacade, loggerFacade); | ||
Assert.assertNull(loginService.getCachedActiveCredential()); | ||
} | ||
|
||
@Test | ||
public void testGoogleLoginService_clearSavedCredentialIfScopesChanged() { | ||
// Persisted credential in the data store has an out-dated scopes. | ||
SortedSet<String> newScope = new TreeSet<String>(Arrays.asList("new scope")); | ||
when(savedOAuthData.getStoredScopes()).thenReturn(newScope); | ||
when(savedOAuthData.getRefreshToken()).thenReturn("fake_refresh_token"); | ||
|
||
GoogleLoginService loginService = new GoogleLoginService(dataStore, uiFacade, loggerFacade); | ||
Assert.assertNull(loginService.getCachedActiveCredential()); | ||
} | ||
|
||
@Test | ||
public void testGoogleLoginService_restoreSavedCredential() { | ||
// Persisted credential in the data store is valid. | ||
when(savedOAuthData.getStoredScopes()).thenReturn(OAUTH_SCOPES); | ||
when(savedOAuthData.getRefreshToken()).thenReturn("fake_refresh_token"); | ||
|
||
GoogleLoginService loginService = new GoogleLoginService(dataStore, uiFacade, loggerFacade); | ||
verify(dataStore, never()).clearStoredOAuthData(); | ||
Assert.assertNotNull(loginService.getCachedActiveCredential()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
....test/src/com/google/cloud/tools/eclipse/appengine/login/TransientOAuthDataStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*******************************************************************************/ | ||
|
||
package com.google.cloud.tools.eclipse.appengine.login; | ||
|
||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.cloud.tools.ide.login.OAuthData; | ||
|
||
import org.eclipse.e4.core.contexts.IEclipseContext; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class TransientOAuthDataStoreTest { | ||
|
||
@Mock private IEclipseContext eclipseContext; | ||
|
||
@Test | ||
public void testLoadOAuthData_emptyStoreReturnsNonNullOAuthData() { | ||
when(eclipseContext.get(anyString())).thenReturn(null); | ||
|
||
OAuthData oAuthData = new TransientOAuthDataStore(eclipseContext).loadOAuthData(); | ||
Assert.assertNotNull(oAuthData); | ||
Assert.assertEquals(null, oAuthData.getAccessToken()); | ||
Assert.assertEquals(null, oAuthData.getRefreshToken()); | ||
Assert.assertEquals(null, oAuthData.getStoredEmail()); | ||
Assert.assertEquals(0, oAuthData.getAccessTokenExpiryTime()); | ||
} | ||
|
||
@Test | ||
public void testSaveAndLoadOAuthData() { | ||
OAuthData inputData = mock(OAuthData.class); | ||
TransientOAuthDataStore dataStore = new TransientOAuthDataStore(eclipseContext); | ||
dataStore.saveOAuthData(inputData); | ||
dataStore.loadOAuthData(); | ||
|
||
ArgumentCaptor<OAuthData> argumentCaptor = ArgumentCaptor.forClass(OAuthData.class); | ||
verify(eclipseContext).set(anyString(), argumentCaptor.capture()); | ||
verify(eclipseContext).get(anyString()); | ||
Assert.assertEquals(inputData, argumentCaptor.getValue()); | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
...in.test/src/com/google/cloud/tools/eclipse/appengine/login/ui/GoogleLoginBrowserTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.