* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 2023, 2025 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
// Consolidate policies
var topologyTemplate = singleEntity.getToscaTopologyTemplate();
if (topologyTemplate != null && topologyTemplate.getPolicies() != null) {
- serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
- serviceTemplate.getToscaTopologyTemplate().setPolicies(new LinkedList<>());
- serviceTemplate.getToscaTopologyTemplate().getPolicies()
- .addAll(singleEntity.getToscaTopologyTemplate().getPolicies());
+ consolidatePolicies(serviceTemplate, topologyTemplate);
}
}
// Preload the specified entities
return createdServiceTemplate;
}
+ /**
+ * Validates the topology template to have policies and add them to the final service template.
+ * @param serviceTemplate the service template to be sent to database
+ * @param topologyTemplate the topology template containing the policies
+ */
+ private static void consolidatePolicies(ToscaServiceTemplate serviceTemplate,
+ ToscaTopologyTemplate topologyTemplate) {
+ if (serviceTemplate.getToscaTopologyTemplate() == null) {
+ serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
+ }
+
+ if (serviceTemplate.getToscaTopologyTemplate().getPolicies() == null) {
+ serviceTemplate.getToscaTopologyTemplate().setPolicies(new LinkedList<>());
+ }
+ serviceTemplate.getToscaTopologyTemplate().getPolicies()
+ .addAll(topologyTemplate.getPolicies());
+ }
+
private ToscaServiceTemplate deserializeServiceTemplate(String entity) throws PolicyApiException, CoderException {
var entityAsStringYaml = ResourceUtils.getResourceAsString(entity);
if (entityAsStringYaml == null) {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024-2025 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.mockito.ArgumentMatchers.any;
-import io.netty.handler.codec.CodecException;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.Assertions;
var mockYamlCoder = Mockito.mock(StandardYamlCoder.class);
Mockito.when(mockYamlCoder.decode((String) any(), any()))
- .thenThrow(new CodecException("fail"));
+ .thenThrow(new CoderException("fail"));
var databaseService = new ApiDatabaseInitializer(mockServiceTemplate, mockPolicyPreload);
Assertions.assertThrows(PolicyApiException.class, databaseService::loadData);