2 * Copyright 2000-2011 JetBrains s.r.o.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package jetbrains.buildServer.nuget.tests.integration;
\r
19 import com.intellij.execution.configurations.GeneralCommandLine;
\r
20 import jetbrains.buildServer.ExecResult;
\r
21 import jetbrains.buildServer.RunBuildException;
\r
22 import jetbrains.buildServer.SimpleCommandLineProcessRunner;
\r
23 import jetbrains.buildServer.agent.BuildFinishedStatus;
\r
24 import jetbrains.buildServer.agent.BuildProcess;
\r
25 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;
\r
26 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;
\r
27 import jetbrains.buildServer.nuget.agent.install.PackageUsages;
\r
28 import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;
\r
29 import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;
\r
30 import jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl;
\r
31 import jetbrains.buildServer.nuget.agent.publish.PackagesPublishRunner;
\r
32 import jetbrains.buildServer.util.FileUtil;
\r
33 import org.jetbrains.annotations.NotNull;
\r
34 import org.jmock.Expectations;
\r
35 import org.testng.Assert;
\r
36 import org.testng.annotations.Test;
\r
38 import java.io.File;
\r
39 import java.io.IOException;
\r
40 import java.util.Arrays;
\r
43 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
44 * Date: 22.07.11 1:25
\r
46 public class PackagesPublishIntegrationTest extends IntegrationTestBase {
\r
49 public void test_publish_packages() throws IOException, RunBuildException {
\r
50 final File pkg = preparePackage();
\r
51 callPublishRunner(pkg);
\r
53 Assert.assertTrue(getCommandsOutput().contains("Your package was uploaded"));
\r
57 public void test_create_mock_package() throws IOException {
\r
58 final File file = preparePackage();
\r
59 System.out.println(file);
\r
62 private File preparePackage() throws IOException {
\r
63 @NotNull final File root = createTempDir();
\r
64 final File spec = new File(root, "SamplePackage.nuspec");
\r
65 FileUtil.copy(getTestDataPath("SamplePackage.nuspec"), spec);
\r
67 GeneralCommandLine cmd = new GeneralCommandLine();
\r
68 cmd.setExePath(Paths.getPathToNuGet().getPath());
\r
69 cmd.setWorkingDirectory(root);
\r
70 cmd.addParameter("pack");
\r
71 cmd.addParameter(spec.getPath());
\r
72 cmd.addParameter("-Version");
\r
73 long time = System.currentTimeMillis();
\r
74 final long max = 65536;
\r
76 for(int i = 0; i <4; i++) {
\r
77 build = (Math.max(1, time % max)) + (build.length() == 0 ? "" : "." + build);
\r
80 cmd.addParameter(build);
\r
81 cmd.addParameter("-Verbose");
\r
83 final ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);
\r
84 System.out.println(result.getStdout());
\r
85 System.out.println(result.getStderr());
\r
87 Assert.assertEquals(0, result.getExitCode());
\r
89 File pkg = new File(root, "SamplePackage." + build + ".nupkg");
\r
90 Assert.assertTrue(pkg.isFile());
\r
94 private void callPublishRunner(@NotNull final File pkg) throws RunBuildException {
\r
96 m.checking(new Expectations(){{
\r
97 allowing(myPublishParameters).getFiles(); will(returnValue(Arrays.asList(pkg.getPath())));
\r
98 allowing(myPublishParameters).getCreateOnly(); will(returnValue(true));
\r
99 allowing(myPublishParameters).getNuGetExeFile(); will(returnValue(Paths.getPathToNuGet()));
\r
100 allowing(myPublishParameters).getPublishSource(); will(returnValue(null));
\r
101 allowing(myPublishParameters).getApiKey(); will(returnValue(getQ()));
\r
103 allowing(myParametersFactory).loadPublishParameters(myContext);will(returnValue(myPublishParameters));
\r
106 NuGetPackagesCollectorImpl collector = new NuGetPackagesCollectorImpl();
\r
107 PackageUsages pu = new PackageUsagesImpl(
\r
109 new NuGetPackagesConfigParser()
\r
112 final PackagesPublishRunner runner = new PackagesPublishRunner(
\r
113 new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()), myParametersFactory);
\r
115 final BuildProcess proc = runner.createBuildProcess(myBuild, myContext);
\r
116 assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);
\r
119 private String getQ() {
\r
120 final int i1 = 88001628;
\r
121 final int universe = 42;
\r
122 final int num = 4015;
\r
123 final String nuget = 91 + "be" + "-" + num + "cf638bcf";
\r
124 return (i1 + "-" + "cb" + universe + "-" + 4 + "c") + 35 + "-" + nuget;
\r