|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Metaform Systems, Inc. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Apache License, Version 2.0 which is available at |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: Apache-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Metaform Systems, Inc. - initial API and implementation |
| 12 | + * |
| 13 | + */ |
| 14 | + |
| 15 | +package org.eclipse.edc.policy.cel.model; |
| 16 | + |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +import java.util.UUID; |
| 20 | + |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; |
| 22 | +import static org.assertj.core.api.Assertions.assertThatCode; |
| 23 | + |
| 24 | +class CelExpressionTest { |
| 25 | + |
| 26 | + @Test |
| 27 | + void build_whenIdNotProvided_shouldGenerateUuid() { |
| 28 | + var expression = CelExpression.Builder.newInstance() |
| 29 | + .leftOperand("leftOperand") |
| 30 | + .expression("true") |
| 31 | + .description("description") |
| 32 | + .build(); |
| 33 | + |
| 34 | + assertThat(expression.getId()).isNotNull(); |
| 35 | + assertThatCode(() -> UUID.fromString(expression.getId())).doesNotThrowAnyException(); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void build_whenIdProvided_shouldKeepIt() { |
| 40 | + var expression = CelExpression.Builder.newInstance() |
| 41 | + .id("my-id") |
| 42 | + .leftOperand("leftOperand") |
| 43 | + .expression("true") |
| 44 | + .description("description") |
| 45 | + .build(); |
| 46 | + |
| 47 | + assertThat(expression.getId()).isEqualTo("my-id"); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void build_whenBuiltTwice_shouldGenerateDifferentIds() { |
| 52 | + var first = CelExpression.Builder.newInstance() |
| 53 | + .leftOperand("leftOperand") |
| 54 | + .expression("true") |
| 55 | + .description("description") |
| 56 | + .build(); |
| 57 | + |
| 58 | + var second = CelExpression.Builder.newInstance() |
| 59 | + .leftOperand("leftOperand") |
| 60 | + .expression("true") |
| 61 | + .description("description") |
| 62 | + .build(); |
| 63 | + |
| 64 | + assertThat(first.getId()).isNotEqualTo(second.getId()); |
| 65 | + } |
| 66 | +} |
0 commit comments