-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance normalize uri #14
Open
scabanovich
wants to merge
1
commit into
tesla:main
Choose a base branch
from
scabanovich:normalize-uri
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -9,7 +9,16 @@ | |
package org.sonatype.m2e.egit.tests; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.net.URISyntaxException; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.core.runtime.SubMonitor; | ||
import org.eclipse.jgit.api.errors.TransportException; | ||
import org.eclipse.jgit.transport.URIish; | ||
import org.eclipse.m2e.scm.MavenProjectScmInfo; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.sonatype.m2e.egit.internal.EgitScmHandler; | ||
|
||
|
@@ -42,4 +51,118 @@ public void testCheckoutNoMaster() throws Exception { | |
|
||
assertWorkspaceProject("git-test"); | ||
} | ||
|
||
public void testNormalizeURI() throws Exception { | ||
EgitScmHandlerExt handler = new EgitScmHandlerExt(); | ||
|
||
String uri = EgitScmHandler.GIT_SCM_ID + "[email protected]:errai/errai.git/errai-common"; | ||
|
||
assertEquals("ssh://[email protected]/errai/errai.git", handler.normalizeUri(uri, false)); | ||
assertEquals("git://github.com/errai/errai.git", handler.normalizeUri(uri, true)); | ||
} | ||
|
||
/** | ||
* Authentication success is mocked. | ||
* Expected: | ||
* - no exception, | ||
* - EgitScmHandler.runCloneOperation() is called, | ||
* - EgitScmHandler.onAuthFailed() is not called. | ||
*/ | ||
public void testAuthFailed1() throws Exception { | ||
EgitScmHandlerExt handler = new EgitScmHandlerExt(); | ||
String url = EgitScmHandlerExt.GIT_SCM_ID + "[email protected]:errai/errai.git/errai-common"; | ||
MavenProjectScmInfo scmInfo = new MavenProjectScmInfo(url, null, null, "HEAD", url, url); | ||
CoreException exc = null; | ||
try { | ||
handler.checkoutProject(scmInfo, null, new NullProgressMonitor()); | ||
} catch (CoreException e) { | ||
exc = e; | ||
} | ||
assertNull(exc); | ||
assertEquals(1, handler.callsOfrunCloneOperation); | ||
assertEquals(0, handler.callsOfonAuthFailed); | ||
} | ||
|
||
/** | ||
* Authentication failure is mocked, user selects cancel to connect anonymously. | ||
* Expected: | ||
* - no exception, | ||
* - EgitScmHandler.runCloneOperation() is called, | ||
* - EgitScmHandler.onAuthFailed() is called. | ||
*/ | ||
public void testAuthFailed2() throws Exception { | ||
EgitScmHandlerExt handler = new EgitScmHandlerExt(true, false); | ||
String url = EgitScmHandlerExt.GIT_SCM_ID + "[email protected]:errai/errai.git/errai-common"; | ||
MavenProjectScmInfo scmInfo = new MavenProjectScmInfo(url, null, null, "HEAD", url, url); | ||
CoreException exc = null; | ||
try { | ||
handler.checkoutProject(scmInfo, null, new NullProgressMonitor()); | ||
} catch (CoreException e) { | ||
exc = e; | ||
} | ||
assertNull(exc); | ||
assertEquals(1, handler.callsOfrunCloneOperation); | ||
assertEquals(1, handler.callsOfonAuthFailed); | ||
} | ||
|
||
/** | ||
* Authentication failure is mocked, user selects ok to connect anonymously. | ||
* Expected: | ||
* - no exception, | ||
* - EgitScmHandler.runCloneOperation() is called twice, | ||
* - EgitScmHandler.onAuthFailed() is called. | ||
*/ | ||
public void testAuthFailed3() throws Exception { | ||
EgitScmHandlerExt handler = new EgitScmHandlerExt(true, true); | ||
String url = EgitScmHandlerExt.GIT_SCM_ID + "[email protected]:errai/errai.git/errai-common"; | ||
MavenProjectScmInfo scmInfo = new MavenProjectScmInfo(url, null, null, "HEAD", url, url); | ||
CoreException exc = null; | ||
try { | ||
handler.checkoutProject(scmInfo, null, new NullProgressMonitor()); | ||
} catch (CoreException e) { | ||
exc = e; | ||
} | ||
assertNull(exc); | ||
assertEquals(2, handler.callsOfrunCloneOperation); | ||
assertEquals(1, handler.callsOfonAuthFailed); | ||
} | ||
|
||
class EgitScmHandlerExt extends EgitScmHandler { | ||
boolean throwAuthFailed = false; | ||
boolean accessAnonymously = false; | ||
|
||
int callsOfonAuthFailed = 0; | ||
int callsOfrunCloneOperation = 0; | ||
|
||
EgitScmHandlerExt() {} | ||
|
||
EgitScmHandlerExt(boolean throwAuthFailed, boolean accessAnonymously) { | ||
this.throwAuthFailed = throwAuthFailed; | ||
this.accessAnonymously = accessAnonymously; | ||
} | ||
|
||
//Make normalizeUri(String, boolean) accessible. | ||
@Override | ||
public String normalizeUri(String uri, boolean avoidSSH) throws URISyntaxException { | ||
return super.normalizeUri(uri, avoidSSH); | ||
} | ||
|
||
//Mock super | ||
@Override | ||
protected void runCloneOperation(URIish uri, File location, String refName, SubMonitor pm) | ||
throws InvocationTargetException, IOException, InterruptedException { | ||
callsOfrunCloneOperation++; | ||
if(throwAuthFailed) { | ||
throwAuthFailed = false; //next time run smoothly. | ||
throw new InvocationTargetException(new TransportException("Auth failed")); | ||
} | ||
} | ||
|
||
//Mock super | ||
@Override | ||
protected boolean onAuthFailed() { | ||
callsOfonAuthFailed++; | ||
return accessAnonymously; | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method run() of type new Runnable(){} must override a superclass method.
This error shows up because the project BREE is J2SE-1.5 and I happen to have a Java 5 JDK, exhibiting the issue.
We should bump the BREE to 1.7, as well as the project version to 0.15.0-SNAPSHOT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.