You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoriesNamespaceTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package org.apache.archiva.metadata.repository.cassandra;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.metadata.model.ProjectMetadata;
  21. import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
  22. import org.apache.archiva.metadata.repository.cassandra.model.Repository;
  23. import org.junit.jupiter.api.AfterEach;
  24. import org.junit.jupiter.api.BeforeEach;
  25. import org.junit.jupiter.api.Test;
  26. import org.junit.jupiter.api.extension.ExtendWith;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. import org.springframework.test.context.ContextConfiguration;
  30. import org.springframework.test.context.junit.jupiter.SpringExtension;
  31. import javax.inject.Inject;
  32. import javax.inject.Named;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. /**
  35. * @author Olivier Lamy
  36. */
  37. @ExtendWith( SpringExtension.class )
  38. @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
  39. public class RepositoriesNamespaceTest
  40. {
  41. private Logger logger = LoggerFactory.getLogger( getClass() );
  42. @Inject
  43. @Named( value = "archivaEntityManagerFactory#cassandra" )
  44. CassandraArchivaManager cassandraArchivaManager;
  45. CassandraMetadataRepository cmr;
  46. @BeforeEach
  47. public void setup()
  48. throws Exception
  49. {
  50. cmr = new CassandraMetadataRepository( null, cassandraArchivaManager );
  51. if ( !cassandraArchivaManager.started() )
  52. {
  53. cassandraArchivaManager.start();
  54. }
  55. CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
  56. }
  57. @AfterEach
  58. public void shutdown()
  59. throws Exception
  60. {
  61. CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
  62. cassandraArchivaManager.shutdown();
  63. }
  64. @Test
  65. public void testMetadataRepo()
  66. throws Exception
  67. {
  68. Repository r = null;
  69. Namespace n = null;
  70. try
  71. {
  72. cmr.updateNamespace( null , "release", "org" );
  73. r = cmr.getRepository( "release" );
  74. assertThat( r ).isNotNull();
  75. assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
  76. n = cmr.getNamespace( "release", "org" );
  77. assertThat( n ).isNotNull();
  78. assertThat( n.getRepository() ).isNotNull();
  79. cmr.updateNamespace( null, "release", "org.apache" );
  80. r = cmr.getRepository( "release" );
  81. assertThat( r ).isNotNull();
  82. assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
  83. cmr.removeNamespace(null , "release", "org.apache" );
  84. assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
  85. assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" );
  86. ProjectMetadata projectMetadata = new ProjectMetadata();
  87. projectMetadata.setId( "theproject" );
  88. projectMetadata.setNamespace( "org" );
  89. cmr.updateProject(null , "release", projectMetadata );
  90. assertThat( cmr.getProjects(null , "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly(
  91. "theproject" );
  92. cmr.removeProject(null , "release", "org", "theproject" );
  93. assertThat( cmr.getProjects(null , "release", "org" ) ).isEmpty();
  94. cmr.removeRepository(null , "release" );
  95. r = cmr.getRepository( "release" );
  96. assertThat( r ).isNull();
  97. }
  98. catch ( Exception e )
  99. {
  100. logger.error( e.getMessage(), e );
  101. throw e;
  102. }
  103. finally
  104. {
  105. CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
  106. }
  107. }
  108. }