Use ConcurrentMapCacheManager as default cachemanager.
Update getrApps endpoint to list array of rapps.
Issue-ID: NONRTRIC-900
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: I82b0be013322abbd835d9313d539919bc954fdf3
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
return new com.oransc.rappmanager.sme.invoker.rest.DefaultApiClient(apiClient);
}
+ @Bean
+ public CacheManager cacheManager() {
+ return new ConcurrentMapCacheManager();
+ }
+
}
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
+import java.util.Collection;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.cache.Cache;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
private final RappService rappService;
@GetMapping
- public ResponseEntity<Cache> getRapps() {
+ public ResponseEntity<Collection<Rapp>> getRapps() {
return ResponseEntity.ok(rappCacheService.getAllRapp());
}
package com.oransc.rappmanager.rest;
+import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@Test
void testGetRapps() throws Exception {
- mockMvc.perform(MockMvcRequestBuilders.get("/rapps")).andExpect(status().isOk());
+ mockMvc.perform(MockMvcRequestBuilders.get("/rapps")).andExpect(status().isOk())
+ .andExpect(jsonPath("$", hasSize(0)));
+ UUID rappId = UUID.randomUUID();
+ Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ rappCacheService.putRapp(rapp);
+ mockMvc.perform(MockMvcRequestBuilders.get("/rapps")).andExpect(status().isOk())
+ .andExpect(jsonPath("$", hasSize(1)));
}
@Test
package com.oransc.rappmanager.models.cache;
import com.oransc.rappmanager.models.rapp.Rapp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.Cache;
private final String RAPP_CACHE = "rapp-cache";
private final CacheManager cacheManager;
- public Cache getAllRapp() {
- return cacheManager.getCache(RAPP_CACHE);
+ public Collection<Rapp> getAllRapp() {
+ Cache cache = cacheManager.getCache(RAPP_CACHE);
+ if (cache != null) {
+ Map<String, Rapp> nativeCache = (Map<String, Rapp>) cache.getNativeCache();
+ return nativeCache.values();
+ }
+ return List.of();
}
public Optional<Rapp> getRapp(String rappId) {