Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Aug 4, 2023
1 parent 020761d commit 1199e72
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,48 @@ public Object[][] expectedParsing() {
"main",
null
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"MyOrg",
"MyProject",
"MyRepo",
null,
null
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.git",
"MyOrg",
"MyProject",
"MyRepo",
null,
null
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.dot.git",
"MyOrg",
"MyProject",
"MyRepo.dot",
null,
null
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"MyOrg",
"MyProject",
"MyRepo",
null,
null
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo-with-hypen",
"MyOrg",
"MyProject",
"MyRepo-with-hypen",
null,
null
},
{"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-", "MyOrg", "MyProject", "-", null, null},
{"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-j.git", "MyOrg", "MyProject", "-j", null, null},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GBmain",
"MyOrg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* Copyright (c) 2012-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.factory.server.azure.devops;

import static java.lang.String.format;
import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;

import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.che.api.factory.server.urlfactory.DevfileFilenamesProvider;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners(MockitoTestNGListener.class)
public class AzureDevOpsURLTest {
private AzureDevOpsURLParser azureDevOpsURLParser;

@BeforeMethod
protected void init() {
azureDevOpsURLParser =
new AzureDevOpsURLParser(mock(DevfileFilenamesProvider.class), "https://dev.azure.com/");
}

@Test(dataProvider = "urlsProvider")
public void checkDevfileLocation(String repoUrl, String fileUrl) {

AzureDevOpsUrl azureDevOpsUrl =
azureDevOpsURLParser
.parse(repoUrl)
.withDevfileFilenames(Arrays.asList("devfile.yaml", "foo.bar"));
assertEquals(azureDevOpsUrl.devfileFileLocations().size(), 2);
Iterator<RemoteFactoryUrl.DevfileLocation> iterator =
azureDevOpsUrl.devfileFileLocations().iterator();
String location = iterator.next().location();
assertEquals(location, format(fileUrl, "devfile.yaml"));
assertEquals(location, format(fileUrl, "foo.bar"));
}

@DataProvider
public static Object[][] urlsProvider() {
return new Object[][] {
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo.dot.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo.dot/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo-with-hypen",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo-with-hypen/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/-",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/-/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/-j.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/-j/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.dot.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo.dot/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo-with-hypen",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo-with-hypen/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/-/items?path=/devfile.yaml&api-version=7.0"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-j.git",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/-j/items?path=/devfile.yaml&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GBmain&_a=contents",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&versionType=branch&version=main&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GBmain",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&versionType=branch&version=main&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag&_a=contents",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&versionType=tag&version=MyTag&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag",
"https://dev.azure.com/MyOrg/MyProject/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&versionType=tag&version=MyTag&api-version=7.0"
},
{
"https://MyOrg@dev.azure.com/MyOrg/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyRepo/_apis/git/repositories/MyRepo/items?path=/devfile.yaml&api-version=7.0"
}
};
}

@Test(dataProvider = "repoProvider")
public void checkRepositoryLocation(String rawUrl, String repoUrl) {
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(rawUrl);
assertEquals(azureDevOpsUrl.getRepositoryLocation(), repoUrl);
}

@DataProvider
public static Object[][] repoProvider() {
return new Object[][] {
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo.git",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo.dot.git",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo.dot"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo-with-hypen",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo-with-hypen"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/-",
"https://dev.azure.com/MyOrg/MyProject/_git/-"
},
{
"https://dev.azure.com/MyOrg/MyProject/_git/-j.git",
"https://dev.azure.com/MyOrg/MyProject/_git/-j"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.git",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.dot.git",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo.dot"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo"
},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo-with-hypen",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/MyRepo-with-hypen"
},
{"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-", "git@ssh.dev.azure.com:v3/MyOrg/MyProject/-"},
{
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-j.git",
"git@ssh.dev.azure.com:v3/MyOrg/MyProject/-j"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GBmain&_a=contents",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GBmain",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag&_a=contents",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag",
"https://dev.azure.com/MyOrg/MyProject/_git/MyRepo"
},
{
"https://MyOrg@dev.azure.com/MyOrg/_git/MyRepo",
"https://dev.azure.com/MyOrg/MyRepo/_git/MyRepo"
}
};
}
}

0 comments on commit 1199e72

Please sign in to comment.