|
|
@ -1,19 +1,32 @@
|
|
|
|
package org.springframework.boot.actuate.info;
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
package org.springframework.boot.actuate.info;
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider.GitInfo.Commit;
|
|
|
|
import org.springframework.boot.actuate.info.ScmGitPropertiesInfoProvider.GitInfo.Commit;
|
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
public class ScmGitPropertiesInfoProviderTest {
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ScmGitPropertiesInfoProviderTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -22,12 +35,12 @@ public class ScmGitPropertiesInfoProviderTest {
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
|
|
|
|
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
assertThat(actual, is(not(nullValue())));
|
|
|
|
assertThat(actual).isNotNull();
|
|
|
|
assertThat((String) actual.get("branch"), is(nullValue()));
|
|
|
|
assertThat((String) actual.get("branch")).isNull();
|
|
|
|
Commit actualCommit = (Commit) actual.get("commit");
|
|
|
|
Commit actualCommit = actual.get("commit");
|
|
|
|
assertThat(actualCommit, is(not(nullValue())));
|
|
|
|
assertThat(actualCommit).isNotNull();
|
|
|
|
assertThat(actualCommit.getId(), is(equalTo("")));
|
|
|
|
assertThat(actualCommit.getId()).isEqualTo("");
|
|
|
|
assertThat(actualCommit.getTime(), is(nullValue()));
|
|
|
|
assertThat(actualCommit.getTime()).isNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -48,12 +61,12 @@ public class ScmGitPropertiesInfoProviderTest {
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
|
|
|
|
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
assertThat(actual, is(not(nullValue())));
|
|
|
|
assertThat(actual).isNotNull();
|
|
|
|
assertThat((String) actual.get("branch"), is(equalTo("develop")));
|
|
|
|
assertThat((String) actual.get("branch")).isEqualTo("develop");
|
|
|
|
Commit actualCommit = (Commit) actual.get("commit");
|
|
|
|
Commit actualCommit = actual.get("commit");
|
|
|
|
assertThat(actualCommit, is(not(nullValue())));
|
|
|
|
assertThat(actualCommit).isNotNull();
|
|
|
|
assertThat(actualCommit.getId(), is(equalTo("e02a4f3")));
|
|
|
|
assertThat(actualCommit.getId()).isEqualTo("e02a4f3");
|
|
|
|
assertThat(actualCommit.getTime(), is(equalTo("2013-04-24T08:42:13+0100")));
|
|
|
|
assertThat(actualCommit.getTime()).isEqualTo("2013-04-24T08:42:13+0100");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -74,25 +87,22 @@ public class ScmGitPropertiesInfoProviderTest {
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
|
|
|
|
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
assertThat(actual, is(not(nullValue())));
|
|
|
|
assertThat(actual).isNotNull();
|
|
|
|
assertThat((String) actual.get("branch"), is(equalTo("develop")));
|
|
|
|
assertThat((String) actual.get("branch")).isEqualTo("develop");
|
|
|
|
Commit actualCommit = (Commit) actual.get("commit");
|
|
|
|
Commit actualCommit = (Commit) actual.get("commit");
|
|
|
|
assertThat(actualCommit, is(not(nullValue())));
|
|
|
|
assertThat(actualCommit).isNotNull();
|
|
|
|
assertThat(actualCommit.getId(), is(equalTo("e02a4f3")));
|
|
|
|
assertThat(actualCommit.getId()).isEqualTo("e02a4f3");
|
|
|
|
assertThat(actualCommit.getTime(), is(nullValue()));
|
|
|
|
assertThat(actualCommit.getTime()).isNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void provide_DoesNotExists_NullReturned() throws Exception {
|
|
|
|
public void provide_DoesNotExists_NullReturned() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
Resource resource = mock(Resource.class);
|
|
|
|
Resource resource = mock(Resource.class);
|
|
|
|
when(resource.exists())
|
|
|
|
given(resource.exists()).willReturn(false);
|
|
|
|
.thenReturn(false);
|
|
|
|
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
ScmGitPropertiesInfoProvider scmGitPropertiesInfoProvider = new ScmGitPropertiesInfoProvider(resource);
|
|
|
|
|
|
|
|
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
Info actual = scmGitPropertiesInfoProvider.provide();
|
|
|
|
assertThat(actual, is(nullValue()));
|
|
|
|
assertThat(actual).isNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|