This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Nexus2196RepositorySummaryTest.java
145 lines (119 loc) · 4.9 KB
/
Nexus2196RepositorySummaryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package org.sonatype.nexus.selenium.nexus2196;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.internal.matchers.StringContains.containsString;
import org.junit.Assert;
import org.junit.Test;
import org.restlet.data.Status;
import org.sonatype.nexus.mock.MockListener;
import org.sonatype.nexus.mock.MockResponse;
import org.sonatype.nexus.mock.NexusTestCase;
import org.sonatype.nexus.mock.SeleniumTest;
import org.sonatype.nexus.mock.pages.RepositorySummary;
import org.sonatype.nexus.mock.pages.RepositoriesEditTabs.RepoKind;
import org.sonatype.nexus.mock.rest.MockHelper;
import org.sonatype.nexus.rest.model.RepositoryMetaResource;
import org.sonatype.nexus.rest.model.RepositoryMetaResourceResponse;
import org.sonatype.nexus.selenium.nexus1815.LoginTest;
public class Nexus2196RepositorySummaryTest
extends SeleniumTest
{
@Test
public void summaryHosted()
throws InterruptedException
{
MockListener ml = listenResult();
RepositorySummary repo = openSummary( "thirdparty", RepoKind.HOSTED );
RepositoryMetaResource meta = ( (RepositoryMetaResourceResponse) ml.getResult() ).getData();
validateRepoInfo( repo, meta );
validateDistMngt( repo, meta );
}
@Test
public void summaryProxy()
throws InterruptedException
{
MockListener ml = listenResult();
RepositorySummary repo = openSummary( "central", RepoKind.PROXY );
RepositoryMetaResource meta = ( (RepositoryMetaResourceResponse) ml.getResult() ).getData();
validateRepoInfo( repo, meta );
}
@Test
public void summaryShadow()
throws InterruptedException
{
MockListener ml = listenResult();
RepositorySummary repo = openSummary( "central-m1", RepoKind.VIRTUAL );
RepositoryMetaResource meta = ( (RepositoryMetaResourceResponse) ml.getResult() ).getData();
validateRepoInfo( repo, meta );
}
@Test
public void byteSize()
throws InterruptedException
{
RepositorySummary repo = mockSize( 512 );
Assert.assertThat( repo.getRepositoryInformation().getValue(), containsString( "512 Bytes" ) );
}
@Test
public void kilobyteSize()
throws InterruptedException
{
RepositorySummary repo = mockSize( 524288 );
Assert.assertThat( repo.getRepositoryInformation().getValue(), containsString( "512 KB" ) );
}
@Test
public void megabyteSize()
throws InterruptedException
{
RepositorySummary repo = mockSize( 536870912 );
Assert.assertThat( repo.getRepositoryInformation().getValue(), containsString( "512 MB" ) );
}
@Test
public void gigabyteSize()
throws InterruptedException
{
RepositorySummary repo = mockSize( 549755813888L );
Assert.assertThat( repo.getRepositoryInformation().getValue(), containsString( "512 GB" ) );
}
private RepositorySummary mockSize( long size )
{
RepositoryMetaResourceResponse result = new RepositoryMetaResourceResponse();
RepositoryMetaResource data = new RepositoryMetaResource();
data.setId( "thridparty" );
data.setFormat( "maven2" );
data.setRepoType( "hosted" );
data.setSizeOnDisk( size );
result.setData( data );
MockHelper.expect( "/repositories/{repositoryId}/meta", new MockResponse( Status.SUCCESS_OK, result ) );
RepositorySummary repo = openSummary( "thirdparty", RepoKind.HOSTED );
return repo;
}
private MockListener listenResult()
{
MockListener ml = new MockListener()
{
};
MockHelper.listen( "/repositories/{repositoryId}/meta", ml );
return ml;
}
private RepositorySummary openSummary( String repoId, RepoKind kind )
{
LoginTest.doLogin( main );
RepositorySummary repo = main.openRepositories().select( repoId, kind ).selectSummary();
repo.getRepositoryInformation().waitToLoad();
return repo;
}
private void validateDistMngt( RepositorySummary repo, RepositoryMetaResource meta )
{
String distMgmt = repo.getDistributionManagement().getValue();
Assert.assertThat( distMgmt, notNullValue() );
Assert.assertThat( distMgmt, containsString( NexusTestCase.nexusBaseURL + "content/repositories/"
+ meta.getId() ) );
}
private void validateRepoInfo( RepositorySummary repo, RepositoryMetaResource meta )
{
String summary = repo.getRepositoryInformation().getValue();
Assert.assertThat( summary, notNullValue() );
Assert.assertThat( summary, containsString( meta.getId() ) );
Assert.assertThat( summary, containsString( meta.getRepoType() ) );
Assert.assertThat( summary, containsString( meta.getFormat() ) );
}
}