|
2 | 2 |
|
3 | 3 | import static com.sap.cds.services.outbox.OutboxService.unboxed; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
5 | 6 | import static org.junit.jupiter.api.Assertions.assertTrue; |
6 | 7 |
|
7 | 8 | import com.sap.cds.services.Service; |
8 | 9 | import com.sap.cds.services.environment.CdsProperties; |
9 | 10 | import com.sap.cds.services.environment.CdsProperties.Messaging.MessagingServiceConfig; |
10 | 11 | import com.sap.cds.services.impl.environment.SimplePropertiesProvider; |
| 12 | +import com.sap.cds.services.outbox.OutboxService; |
11 | 13 | import com.sap.cds.services.runtime.CdsRuntimeConfigurer; |
12 | 14 | import java.util.List; |
13 | 15 | import java.util.stream.Collectors; |
@@ -140,4 +142,87 @@ void testServiceConfigurationWithInvalidBinding() { |
140 | 142 |
|
141 | 143 | assertTrue(services.isEmpty(), "Expected no services to be configured with invalid binding"); |
142 | 144 | } |
| 145 | + |
| 146 | + @Test |
| 147 | + void testServiceConfigurationWithoutSkipManagementConfigured() { |
| 148 | + CdsProperties properties = new CdsProperties(); |
| 149 | + MessagingServiceConfig config = new MessagingServiceConfig("cfg"); |
| 150 | + config.setBinding("my-aem-instance"); |
| 151 | + config.getOutbox().setEnabled(false); |
| 152 | + properties.getMessaging().getServices().put(config.getName(), config); |
| 153 | + |
| 154 | + CdsRuntimeConfigurer configurer = |
| 155 | + CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties)); |
| 156 | + |
| 157 | + configurer.serviceConfigurations(); |
| 158 | + configurer.eventHandlerConfigurations(); |
| 159 | + |
| 160 | + List<AemMessagingService> services = |
| 161 | + configurer |
| 162 | + .getCdsRuntime() |
| 163 | + .getServiceCatalog() |
| 164 | + .getServices() |
| 165 | + .map(OutboxService::unboxed) |
| 166 | + .filter(srv -> srv.getClass().equals(AemMessagingService.class)) |
| 167 | + .map(srv -> (AemMessagingService) srv) |
| 168 | + .toList(); |
| 169 | + |
| 170 | + assertFalse(services.stream().findFirst().get().getSkipManagement()); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + void testServiceConfigurationWithDisabledSkipManagement() { |
| 175 | + CdsProperties properties = new CdsProperties(); |
| 176 | + MessagingServiceConfig config = new MessagingServiceConfig("cfg"); |
| 177 | + config.setBinding("my-aem-instance"); |
| 178 | + config.getOutbox().setEnabled(false); |
| 179 | + config.getConnection().getProperties().put("skip-management", "false"); |
| 180 | + properties.getMessaging().getServices().put(config.getName(), config); |
| 181 | + |
| 182 | + CdsRuntimeConfigurer configurer = |
| 183 | + CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties)); |
| 184 | + |
| 185 | + configurer.serviceConfigurations(); |
| 186 | + configurer.eventHandlerConfigurations(); |
| 187 | + |
| 188 | + List<AemMessagingService> services = |
| 189 | + configurer |
| 190 | + .getCdsRuntime() |
| 191 | + .getServiceCatalog() |
| 192 | + .getServices() |
| 193 | + .map(OutboxService::unboxed) |
| 194 | + .filter(srv -> srv.getClass().equals(AemMessagingService.class)) |
| 195 | + .map(srv -> (AemMessagingService) srv) |
| 196 | + .toList(); |
| 197 | + |
| 198 | + assertFalse(services.stream().findFirst().get().getSkipManagement()); |
| 199 | + } |
| 200 | + |
| 201 | + @Test |
| 202 | + void testServiceConfigurationWithEnabledSkipManagement() { |
| 203 | + CdsProperties properties = new CdsProperties(); |
| 204 | + MessagingServiceConfig config = new MessagingServiceConfig("cfg"); |
| 205 | + config.setBinding("my-aem-instance"); |
| 206 | + config.getOutbox().setEnabled(false); |
| 207 | + config.getConnection().getProperties().put("skipManagement", "true"); |
| 208 | + properties.getMessaging().getServices().put(config.getName(), config); |
| 209 | + |
| 210 | + CdsRuntimeConfigurer configurer = |
| 211 | + CdsRuntimeConfigurer.create(new SimplePropertiesProvider(properties)); |
| 212 | + |
| 213 | + configurer.serviceConfigurations(); |
| 214 | + configurer.eventHandlerConfigurations(); |
| 215 | + |
| 216 | + List<AemMessagingService> services = |
| 217 | + configurer |
| 218 | + .getCdsRuntime() |
| 219 | + .getServiceCatalog() |
| 220 | + .getServices() |
| 221 | + .map(OutboxService::unboxed) |
| 222 | + .filter(srv -> srv.getClass().equals(AemMessagingService.class)) |
| 223 | + .map(srv -> (AemMessagingService) srv) |
| 224 | + .toList(); |
| 225 | + |
| 226 | + assertTrue(services.stream().findFirst().get().getSkipManagement()); |
| 227 | + } |
143 | 228 | } |
0 commit comments